horothesun
horothesun

Reputation: 427

Pop UIViewController with custom "dismiss modal"-like animation

I'm trying to customise the transition animations of a UINavigationController push/pop based navigation in a way that simulates presenting/dismissing UIViewControllers.

Here's an example of the standard animations:

enter image description here

I was able to obtain the same "slide up from the bottom" push animation implementing a custom vertical UIStoryboardSegue.

The hard part is to implement the counterpart pop animation. The best I'm able to get is the following:

enter image description here

Here's a slow motion version of the same effect:

enter image description here

From the previous animation you can appreciate that it's different from the standard dismiss modal animation mainly because the Bubblegum screen shouldn't slide from top to bottom, but should be already present behind the Navy screen during the pop.

This is the code I've used to create the fake dismiss modal animation:

class FakeModalNavigationController: UINavigationController {

    fileprivate static let unwindToBubblegumScreenSegueID = "unwindToBubblegumScreenSegueID"

    override func unwind(for unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
        if unwindSegue.identifier == type(of: self).unwindToBubblegumScreenSegueID {
            popViewControllerAnimatedFromBottom(subsequentVC)
        }
    }

    fileprivate func popViewControllerAnimatedFromBottom(_ viewControllerToPop: UIViewController) {
        let transition = CATransition()
        transition.duration = 0.25
        transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        transition.type = kCATransitionPush
        transition.subtype = kCATransitionFromBottom
        view.layer.add(transition, forKey: nil)
        popViewController(animated: false)
    }
}

Thanks in advance for answers and comments!

Upvotes: 1

Views: 2379

Answers (1)

Martin Kostov
Martin Kostov

Reputation: 21

Try to use:

transition.type = kCATransitionReveal
transition.subtype = kCATransitionFromBottom

Upvotes: 2

Related Questions