0

In iOS 13 and above the default modal presentation style of a view controller allows you to dismiss it interactively. The thing is I need to know when a view controller is dismissed, to perform some actions.

Unfortunately, I cannot use viewWllDisappear and viewDidDisappear because there are other screens that are presented from that view controller, so those will be called as well.

Is there any way to handle an interactive dismiss of a View Controller?

EDIT; What I mean, is if there’s a way to handle this kind of dismiss. enter image description here

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
Sotiris Kaniras
  • 520
  • 1
  • 12
  • 30
  • Is there a reason you can't simply set up a *separate* view controller? Or have I misunderstood the problem? – West1 May 09 '21 at 14:49
  • Hi @West1! Please take a look at my edit – Sotiris Kaniras May 09 '21 at 15:00
  • Not being able to use the API functions for their intended purpose is a code smell. – Bradley Thomas May 09 '21 at 15:03
  • But those 2 functions can be called for presenting a screen too, not just when a screen gets dismissed. I would need to add more logic to implement that, that’s why I'm trying to find out if Apple's API offers a handler for Interactive dismissal. – Sotiris Kaniras May 09 '21 at 15:09

1 Answers1

1

Your viewDidDisappear() will do the work for this as it will only be called for the viewController that you are dismissing.

You can try using the deinit() function as well.

You can also track this property on your viewController

var isMovingToParent: Bool

A Boolean value indicating whether the view controller is being moved to a parent view controller.

Or you can show your controller full screen while instantiating it.

For example,

 @objc fileprivate func continueButtonDidPress(){
   //TODO:- Go to Feed
    let viewController = MainViewController()
    viewController.modalTransitionStyle = .flipHorizontal
    viewController.modalPresentationStyle = .fullScreen
    present(viewController, animated: true, completion: nil)
}
Rohit
  • 41
  • 4