Sogenannte wird Ich versuche, einen animierten Übergang zwischen Viewcontrollers auf tvOS 10.UIViewControllerTransitioningDelegate auf tvOS nicht
Das UIViewControllerTransitioningDelegate Protokoll zur Verfügung zu tun, auf tvOS so dass ich davon ausgegangen, ich es auch animieren könnte. Aus irgendeinem Grund wird jedoch keine der Funktionen aufgerufen, wenn der neue Viewcontroller präsentiert wird.
Ich habe keine Ahnung, was ich falsch mache, da ich im Grunde genau dasselbe auf iOS mache. Hier
ist der Code Ich verwende:
Presenting Code
func showStuff() {
let viewController = ResultViewController()
viewController.transitioningDelegate = ResultViewControllerTransitionManager()
viewController.modalPresentationStyle = .custom
navigationController?.present(viewController, animated: true, completion: nil)
}
Transition Delegate
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
}
}
Ich bevorzuge es, die Animationsmethoden in einer separaten Klasse zu halten. So kann ich es an anderen Stellen wiederverwenden und den ursprünglichen Viewcontroller sauberer halten. – Houwert