我按照指南创建自定义转换,他确实创建了一个看起来像的NSObject:
class CustomNavigationAnimationController: NSObject, UINavigationControllerDelegate {
func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if fromVC.isKindOfClass(VC2) {
return showTrans()
} else if fromVC.isKindOfClass(VC3){
return dismissTrans()
} else {
return nil
}
}
}
然后在另一个文件中,他创建了两个带有showTrans / dismissTrans函数的类,类看起来像:
class showTrans: NSObject, UIViewControllerAnimatedTransitioning {
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView()
let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!
let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
containerView?.addSubview(fromVC.view)
containerView?.addSubview(toVC.view)
toVC.view.alpha = 0
UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: {
toVC.view.alpha = 1
}) { (finished: Bool) in
transitionContext.completeTransition(true)
}
}
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.7
}
在视频的最开始,他进入故事板并点击他的导航控制器,顶部有4个按钮,用于导航控制器/第一响应者/退出/代表。他单击委托按钮并将Nav Bar的委托设置为CustomNavigationAnimationController类。当我点击导航控制器时,我只会将导航控制器/第一响应者/退出按钮放在顶部。
如何将类/转换代码连接到导航控制器?