2016-06-23 11 views

答えて

2

私はこれを数ヶ月前に行っています。
1.トランジションをカスタマイズします。例えば、これは、(そうポップなど)プッシュである:

class BWFlipTransionPush: NSObject, UIViewControllerAnimatedTransitioning { 

    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { 
     return 0.5 
    } 

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
     let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) 
     let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! // as! UBPasswordLoginViewController 
     let container = transitionContext.containerView() 
     container!.addSubview(toVC.view) 
     container!.bringSubviewToFront(fromVC!.view) 

     //改变m34 
     var transfrom = CATransform3DIdentity 
     transfrom.m34 = -0.002 
     container!.layer.sublayerTransform = transfrom 

     //设置anrchPoint 和 position 
     let initalFrame = transitionContext.initialFrameForViewController(fromVC!) 
     toVC.view.frame = initalFrame 
     fromVC!.view.frame = initalFrame 
     toVC.view.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI_2), 0, 1, 0) 



     //动画 
     UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {() -> Void in 
       fromVC!.view.layer.transform = CATransform3DMakeRotation(CGFloat(-M_PI_2), 0, 1, 0) 
      }) { (finished: Bool) -> Void in 
       container?.bringSubviewToFront(toVC.view) 
       UIView.animateWithDuration(self.transitionDuration(transitionContext), delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {() -> Void in 
        toVC.view.layer.transform = CATransform3DIdentity 
       }) { (finished: Bool) -> Void in 

        fromVC!.view.layer.transform = CATransform3DIdentity 
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) 
       } 

     } 
    } 
} 

2.Setデリゲートのためにこのようなあなたのナビゲーションコントローラ:

override func viewDidLoad() { 
     super.viewDidLoad() 
     navigationController?.delegate = self 
    } 

3.Implementデリゲート機能:

func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    switch operation { 
    case .Pop: 
     return nil // you should return customized pop 
    case .Push: 
     return BWFlipTransionPush() 
    default: 
     return nil 
    } 
} 

更新
ここにフリップポップがあります。

class BWFlipTransionPop: NSObject, UIViewControllerAnimatedTransitioning { 

    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { 
     return 0.5 
    } 

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
     let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)! // as! UBPasswordLoginViewController 
     let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) 
     let container = transitionContext.containerView() 
     container!.addSubview(toVC!.view) 

     //改变m34 
     var transfrom = CATransform3DIdentity 
     transfrom.m34 = -0.002 
     container!.layer.sublayerTransform = transfrom 

     //设置anrchPoint 和 position 
     let initalFrame = transitionContext.initialFrameForViewController(fromVC) 
     toVC!.view.frame = initalFrame 
     toVC!.view.layer.transform = CATransform3DMakeRotation(CGFloat(-M_PI_2), 0, 1, 0) 


     //动画 
     UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {() -> Void in 
      fromVC.view.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI_2), 0, 1, 0) 
     }) { (finished: Bool) -> Void in 
      container?.bringSubviewToFront(toVC!.view) 
      UIView.animateWithDuration(self.transitionDuration(transitionContext), delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {() -> Void in 
       toVC!.view.layer.transform = CATransform3DIdentity 
      }) { (finished: Bool) -> Void in 


       fromVC.view.layer.transform = CATransform3DIdentity 
       transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) 
      } 

     } 

    } 
} 
+0

徹底的な回答をいただきありがとうございます。 – SwiftyJD

関連する問題

 関連する問題