0

Ich habe eine UINavigationController Setup und erwarte eine benutzerdefinierte Animation für Pop/Push-Ansichten damit verwenden. Ich habe vorher benutzerdefinierte Übergänge ohne Problem verwendet, aber in diesem Fall finde ich tatsächlich keine Werte in meinem 'von' und 'zu' UIViewControllers.Inside UIViewControllerAnimatedTransitionierung Delegate, die TransitionContext.fromViewController ist Null

Mein Setup ist sehr ähnlich zu diesem SO Post

Individuelle DataEntryViewController

class DataEntryViewController : UIViewController, DataEntryViewDelegate, UINavigationControllerDelegate { 

    func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {   
     let animator = DataEntryTransitionAnimator() 
     animator.duration = 2 
     return animator 
    } 
} 

Individuelle BaseTransitionAnimator

class BaseTransitionAnimator : NSObject, UIViewControllerAnimatedTransitioning { 

    var duration : NSTimeInterval = 0.5    // default transition time of 1/2 second 
    var appearing : Bool = true      // is the animation appearing (or disappearing) 

    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { 
     return duration 
    } 

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
     assert(true, "animateTransition MUST be implemented by child class") 
    } 
} 

Unterklasse TransitionAnimator

class DataEntryTransitionAnimator : BaseTransitionAnimator { 

    override func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
     let containerView = transitionContext.containerView() 
     let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewKey) as! DataEntryViewController 
     let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewKey) as! DataEntryViewController 
     let duration = transitionDuration(transitionContext) 

     // do fancy animations 
    } 
} 

die Verwendung der obigen beiden fromVC und toVC sind nil

Wie ist es möglich, dass die transitionContext ungültig Zeiger auf die ‚zu‘ hat und ‚von‘ UIViewControllers?

Antwort

3

Sie verwenden UITransitionContextFromViewKey aber Sie müssen UITransitionContextFromViewControllerKey

gleiche gilt für "bis"

+0

verwenden: facepalm: Ha, danke. Ich debugging auf der Kommandozeile UND schaute im Debug-Fenster auch, schwor, dass es für die VCs nil gezeigt hat, aber wahrscheinlich aufgrund von Extras sah es einfach komisch aus. Ich gewöhne mich immer noch an Swift. – MobileVet

+0

Keine Sorge! Ein einfacher Tippfehler, der leicht zu übersehen ist. – Mackarous

+0

danke so viel ich hatte genau das gleiche Problem xD – coolcool1994