How to change the Push and Pop animations in a navigation based app

前端 未结 25 1588
清酒与你
清酒与你 2020-11-22 12:46

I have a navigation based application and I want to change the animation of the push and pop animations. How would I do that?

Edit 2018

Ther

25条回答
  •  生来不讨喜
    2020-11-22 13:16

    @Magnus answer, only then for Swift (2.0)

        let transition = CATransition()
        transition.duration = 0.5
        transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        transition.type = kCATransitionPush
        transition.subtype = kCATransitionFromTop
        self.navigationController!.view.layer.addAnimation(transition, forKey: nil)
        let writeView : WriteViewController = self.storyboard?.instantiateViewControllerWithIdentifier("WriteView") as! WriteViewController
        self.navigationController?.pushViewController(writeView, animated: false)
    

    Some sidenotes:

    You can do this as well with Segue, just implement this in prepareForSegue or shouldPerformSegueWithIdentifier. However, this will keep the default animation in it as well. To fix this you have to go to the storyboard, click the Segue, and uncheck the box 'Animates'. But this will limit your app for IOS 9.0 and above (atleast when I did it in Xcode 7).

    When doing in a segue, the last two lines should be replaced with:

    self.navigationController?.popViewControllerAnimated(false)
    

    Even though I set false, it kind of ignores it.

提交回复
热议问题