私は WYPopoverController を組み込んだアプリに取り組んでおり、本来あるべき場所でうまく機能します。組み込みのプッシュ/ポップではなく、2 つのコントローラー間にカスタム アニメーションを追加したいと考えています。
FROM および TO コントローラーを含むナビゲーション コントローラーでは、WYPopoverController に関連することは何もしません。コントローラーの FROM および TO でも同様です。
実際のアニメーションを処理する非常にシンプルなアニメーター クラスであるナビゲーション コントローラー デリゲートを実装しました。
public class NavigationControllerDelegate: NSObject, UINavigationControllerDelegate {
let animator = Animator()
public func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == UINavigationControllerOperation.Pop {
return self.animator
}
return nil
}
}
アニメータークラス:
class Animator: NSObject, UIViewControllerAnimatedTransitioning {
public func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
return 0.33
}
public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!
transitionContext.containerView().addSubview(toVC.view)
toVC.view.alpha = 0
UIView.animateWithDuration(self.transitionDuration(transitionContext), animations: { () -> Void in
fromVC.view.transform = CGAffineTransformMakeScale(0.1, 0.1)
toVC.view.alpha = 1
}) { (finished) -> Void in
fromVC.view.transform = CGAffineTransformIdentity
transitionContext.completeTransition(!transitionContext.transitionWasCancelled())
}
}
}
FROM コントローラーで、ナビゲーション デリゲートを初期化します
override public func viewDidLoad() {
super.viewDidLoad()
// ... some other code here
self.navigationController?.delegate = NavigationControllerDelegate()
}
(コレクション)セルをタップしてTOコントローラーに移動したい時点まで、すべてがコンパイルされて実行されます。その時点で、アプリがエラーでクラッシュします: -[CALayer navigationController:animationControllerForOperation:fromViewController:toViewController:]: unrecognized selector sent to instance 0x7fc72e53e970
ブレークポイントを追加し、sizzled_pushViewController:animated:
UINavigationController のメソッド内に行き着きました。正直なところ、私はこの問題にどのようにアプローチすればよいかわかりません。