我下面的指導,以創建自定義轉換和他所做的就是創建一個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個按鈕。他單擊委託按鈕並將導航欄的委託設置爲CustomNavigationAnimationController類。當我點擊導航控制器時,我只能看到頂部的Nav Controller/First Responder/Exit按鈕。
如何將類/轉換代碼連接到導航控制器?
你可以看到一個箭頭標記在故事板上導航控制器的快照。單擊該箭頭標記,您將看到導航欄,然後右鍵單擊該標記以獲取委託。讓我知道它是否工作.. – Janmenjaya
不知何故,我完全錯過了,他已經拖入一個NSObject的頂部位,然後像你說的拖動委託。非常感謝! –