我正在寫UIStoryboardSegue自定義塞格。我使用CATransition來創建一個從左到右自定義動畫的權利。如果我使用sourceViewController.navigationController?.pushViewController(destinationViewController, animated: false);
,它不會將我帶到第二個視圖。它僅執行左側動畫的權利並保留在第一個視圖上。我調試了這段代碼,發現sourceViewController.navigationController爲零。在第一個視圖和第二個視圖之間有一個UINavigationController。NavigationController.pushViewController在自定義塞格不工作 - 斯威夫特2.0 - iOS 9.1
我也嘗試用sourceViewController.presentViewController(destinationViewController, animated: false, completion: nil);
替換這行代碼。過渡確實發生,但發生得太快,我無法看到左側動畫的權利。
我在這個UIStoryboardSegue完整的代碼如下:
override func perform() {
let sourceViewController = self.sourceViewController as UIViewController;
let destinationViewController = self.destinationViewController as UIViewController;
let transition: CATransition = CATransition()
transition.duration = 0.25;
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
sourceViewController.view.layer.addAnimation(transition, forKey: "kCATransition")
sourceViewController.navigationController?.pushViewController(destinationViewController, animated: false);
}
非常感謝您的幫助
這個答案可能是正確的,但很難解釋。請填寫答案 – voghDev