dimanche 2 août 2015

Pushing a navigation controller is not supported in iOS 7.1, but works fine in iOS 8

I'm using this code snippet to make a left to right segue:

    var src: UIViewController = self.sourceViewController as! UIViewController
    var dst: UIViewController = self.destinationViewController as! UIViewController
    var transition: CATransition = CATransition()
    var timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.duration = 0.35
    transition.timingFunction = timeFunc
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromLeft
    src.navigationController!.view.layer.addAnimation(transition, forKey: kCATransition)
    //src.navigationController!.presentViewController(dst, animated: true, completion: {})
    src.navigationController!.pushViewController(dst, animated: false)

But src.navigationController!.pushViewController(dst, animated: false) when using iOS 7.1 simulator causes 'Pushing a navigation controller is not supported' error, but on iOS 8 it works just fine.

When I try to replace this line with src.navigationController!.presentViewController(dst, animated: true, completion: {}) everything works weird. At first, I can't get proper animation, because it starts to combine default animation with custom. Also after some segues src.navigationController becomes nil for no reason and code crashes.

So, can i use src.navigationController!.pushViewController(dst, animated: false) in iOS 7? Or am I using src.navigationController!.presentViewController(dst, animated: true, completion: {}) the wrong way, that it leads to navigation controller becoming nil?

Aucun commentaire:

Enregistrer un commentaire