我正在按照指南创建自定义转换,他确实创建了一个 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
}
在视频的最开始,他进入 Storyboard并单击他的导航 Controller ,顶部有 4 个按钮用于导航 Controller /第一响应者/退出/委托(delegate)。他单击委托(delegate)按钮并将导航栏的委托(delegate)设置为 CustomNavigationAnimationController 类。当我点击导航 Controller 时,我只会在顶部看到导航 Controller /急救员/退出按钮。
如何将类/转换代码连接到导航 Controller ?
最佳答案
在 Storyboard 中单击 Navigation Controller。将对象库中的 NSObject 添加到您的导航栏。在 View 的顶部,您可以看到四个按钮(如您在问题中所说 - Nav Controller/First Responder/NSObject/Exit buttons)。右键单击第一个按钮。您将获得导航 Controller 操作列表。在 Outlets 下选择 delegate 并拖动到 NSObject。将 NSObject 连接到您的类。
关于ios - 设置导航 Controller 的委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39403399/