Beginning iOS Animations · Dismiss Animation | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9051-beginning-ios-animations/lessons/26

@catie, @jessycatterwaul, why do we manage both present and dismiss functions in ViewController?
I supposed we would to code presenting function in ViewController, while dismissing function in HerbDetailsViewController.

@catie, @jessycatterwaul, help! :scream: After tapping DetailedHerbView it does not shrink back and stays on the scream. If tapping the screen at the area of scroll view debugger prints:
2020-01-30 02:20:45.620143+0500 BeginnerCook[30710:11524865] [Assert] UIKit Internal bug: Unbalanced call to _endOcclusion, please file a Radar on UIKit | Presentations with reproduction steps if you hit this !

Hi there! Thanks for letting us know. I made some assumptions about the view hierarchy that seem to no longer be true in iOS13. To sum it up, you can’t rely on a to view existing when dismissing.

I’ve fixed the issue and updated the download materials for this episode, and I’m going to go ahead and do the same for the rest of this part of the course. I also left MARK: comments in the End project for this episode to show what is different than the video.


Regarding why both the present and dismiss functions are in ViewController:

It’s the presenting view controller’s job to dismiss any other view controllers it presents. It’s true that the dismissal is being called from HerbDetailsViewController in the actionClose method. But, the actual dismiss method is handled by presenting view controller, which in this case is ViewController:

 @objc func actionClose(_ tap: UITapGestureRecognizer) {
    👉presentingViewController?.dismiss(animated: true, completion: nil)
  }

You can read a bit more about that general concept in the documentation for UIViewController: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621505-dismiss

A transitioning delegate works in a similar way. It specifies the presentation and dismissal animation controllers. In this case, ViewController is also acting as its own UIViewControllerTransitioningDelegate.

1 Like

Thank you very much! It is much more clear now. :smiley: