2016-12-23 7 views
2

私のアプリケーションがあるView Controllerから別のView Controllerに移行する際にカスタムアニメーションを実装しようとしていますが、何らかの理由でカスタムアニメーションクラスのanimateTransition関数が呼び出されません。transitioningDelegateはSegueトランジション後に決して呼び出されません

私はXcode 8を使用していて、Swift 3で書いています。私がやり遂げようとしている問題は、この関数が決して呼び出されないということです。実際のアニメーションは、今のところ、ここではその

は遷移アニメーションを処理する必要があり、私のCustomPresentAnimationControllerクラス、内のコードです...ここで

import UIKit 

class CustomPresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate, UINavigationControllerDelegate { 

    let duration = 0.5 

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 
     print("Checking duration") 
     return duration 
    } 

    func animationController(forPresented presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     print("This ran 1") 
     return self 
    } 

    func presentationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     print("This ran 2") 
     return self 
    } 

    func animationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     print("This ran 3") 
     return self 
    } 

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 

     print("It's working!") 

     guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else { 
      return 
     } 

     guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else { 
      return 
     } 

     let container = transitionContext.containerView 

     let screenOffDown = CGAffineTransform(translationX: 0, y: -container.frame.height) 

     let screenOffUp = CGAffineTransform(translationX: 0, y: container.frame.height) 

     container.addSubview(fromView) 
     container.addSubview(toView) 

     toView.transform = screenOffUp 

     UIView.animate(withDuration: duration, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: [], animations: { 

      fromView.transform = screenOffDown 
      fromView.alpha = 0.5 
      toView.transform = CGAffineTransform.identity 
      toView.alpha = 1 

     }) { (success) in 
      transitionContext.completeTransition(success) 
     } 

    } 

} 

は(私のビューコントローラの参照の両方)私のViewControllerのコードです。.. 。

import UIKit 

class ViewController: UIViewController, UINavigationControllerDelegate, UIViewControllerTransitioningDelegate { 

    override func viewDidLoad() { 
     if transitioningDelegate != nil { 
      print("Should do something...") 
      print(transitioningDelegate) 
     } else { 
      print("Transitioing Delegate set to nil") 
     } 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
     self.navigationController?.delegate = self 

    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
    let customPresentAnimationController = CustomPresentAnimationController() 
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     print("doing our custom transition") 
     print(segue.destination) 
     let destination = segue.destination 
     destination.transitioningDelegate = customPresentAnimationController 
    } 
} 

私がコードを実行し、私のSeance View Controllerにリンクしているボタンをクリックして、 'Present Modional'に設定すると、ビューは標準トランジションで変更されます(下からスライドします)。以下は、Xcodeのにプリントアウトされます。

Transitioing Delegate set to nil 
doing our custom transition 
<moduleView.ViewController: 0x7fe427f09a40> 
Should do something... 
Optional(<moduleView.CustomPresentAnimationController: 0x60800002e980>) 

明らかに最初の行は、単に最初のビュー負荷としてある、すべての残りの部分は私のtransitionDelegateがセグエ先に設定されていることを示しており、実際に2番目のビューとして読み込まれますtransitionDelegateはCustomPresentAnimationControllerに設定されていますが、それらの関数から何も出力されないので、そのクラスの関数は一度も呼び出されません。

答えて

0

デリゲートを実装するためのメソッドシグネチャが、更新されたSwift 3の構文と一致していることを確認します。

関連する問題