所以我試圖做tvOS 10UIViewControllerTransitioningDelegate不會被調用
的UIViewControllerTransitioningDelegate協議可在tvOS,所以我認爲我可以製作動畫以及viewcontrollers之間的動畫過渡。但出於某種原因,在展示新的視圖控制器時,沒有任何功能會被調用。
我不知道我在做什麼錯,因爲我在iOS上做的基本上完全相同。
這裏是我使用的代碼:
呈現代碼
func showStuff() {
let viewController = ResultViewController()
viewController.transitioningDelegate = ResultViewControllerTransitionManager()
viewController.modalPresentationStyle = .custom
navigationController?.present(viewController, animated: true, completion: nil)
}
過渡委託
class ResultViewControllerTransitionManager: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {
var duration = 0.5
var isPresenting = false
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else {return}
guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else {return}
(...)
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
isPresenting = false
return self
}
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
isPresenting = true
return self
}
}
我更喜歡將動畫方法保留在單獨的類中。所以我可以在其他地方重複使用它,並保持原始視圖控制器更加清潔。 – Houwert