ios - 设置导航 Controller 的委托(delegate)?

标签 ios swift uinavigationcontroller

我正在按照指南创建自定义转换,他确实创建了一个 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/

相关文章:

ios - 如何回到第一 View

ios - 收到远程通知时推送 UIViewController

ios - 我从我的 mac 中删除了所有 IOS 模拟器,现在我无法添加任何一个

ios - Afnetworking multipart/formdata 返回请求在 ios 11 中失败,但在 ios 10 中工作正常

ios - 如何让图像在 iOS 的分页 ScrollView 中缩放?

ios - 在 obj c 中快速导入 Swift 非 View Controller 类

ios - 关于创建新的 tableView 单元格,Apple 术语 "registers"是什么意思?

ios - 每当我对嵌入 ScrollView 的内容 View 进行约束时,它就会占用 View Controller 顶部的空间?

ios - 什么时候检查 "This Application Uses Encryption"框?

arrays - 如何获取数组中元素的位置