Swift 自定义转场

1.设置转场代理

myView.transitioningDelegate = self

2.设置转场动画样式

my.modalPresentationStyle = .Custom

3.弹出菜单

presentCiewController(myView, animated: true, comletion: nil)

extension 实现代理方法

func animationControllerForPresentedController(presented:UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {

return MyPresentationController(presentedViewController:  presented,presentingViewController: presenting) //自定义的presentationController类

}

自定义presentationController

class MyPresentationController : UIPresentationController
{

 override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {

  super.init(presentedViewController: presentedViewController, presentingViewController: presentingController)

 }


//用于布局转场动画弹出的视图

override func containerViewWillLayoutSubviews(){

// containerView 容器视图

// presentedView() 拿到弹出的视图

presentedView()?.frame = CGRect(x: 100, y: 45, width: 200, height: 200)

}

}

你可能感兴趣的:(Swift 自定义转场)