swiftuimodalpresentationstyle

What's the difference between currentContext and overCurrentContext?


The docs for both currentContext and overCurrentContext have an identical description.

The differences I can spot are:

Is there any other difference?


Solution

  • It's exactly the same as the difference between fullScreen and overFullScreen. The first removes the view from the area it covers; the second doesn't, it merely covers it.

    (In both cases, this difference is easy to see visually if your presented view controller's main view's background color has some transparency. But the differences for behavior are even more important; some views become unhappy when they are abruptly ripped out of the view hierarchy, so it could be better to leave them in place and use the .over variant.)

    With currentContext, after dismissing the presented view controller, viewWillAppear of the covered view controller gets called (which doesn't have to be the view controller that provides the context). With overCurrentContext it does not get called.

    That's just a consequence of what I just said. With over, viewWillAppear is not called on dismissal because the view never disappeared in the first place; it just sat there behind the presented view. Again, that's completely parallel to fullScreen and overFullScreen.