2016-11-03 11 views
0

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 
    } 
} 

Antwort

0

Also scheinbar Initialisierung des animationmanager in der showStuff()-Funktion war das Problem. Speichern Sie es als eine Eigenschaft in der Hauptansicht Controller und übergeben Sie es hat funktioniert.

0

Sie implementieren können UIViewControllerAnimatedTransitioning und UIViewControllerTransitioningDelegate Protokolle Seite deinen ersten View-Controller. Ihre erste UIViewController kann den folgenden Code:

class ViewController: UIViewController, UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning { 
    func showStuff() { 
     let viewController = ResultViewController() 
     viewController.transitioningDelegate = self 
     viewController.modalPresentationStyle = .custom 
     self.present(viewController, animated: true, completion: nil) 
    } 
    var duration = 0.5 
    var isPresenting = false 
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return self 
    } 

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return self 
    } 
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 

     return 2.0 
    } 
    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} 

    } 
} 

Auch stelle ich einen neuen Controller von der ersten (nicht von der Navigation).

+0

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

Verwandte Themen