3

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

The differences I can spot are:

  • since when they are available:

    @available(iOS 3.2, *)
    case currentContext
    
    @available(iOS 8.0, *)
    case overCurrentContext
    
  • 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.

Is there any other difference?

Manuel
  • 14,274
  • 6
  • 57
  • 130

1 Answers1

10

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • In my case it's a navigation controller with some views in its stack. The top most view presents, the navigation controller is by default defining the presentation context. Does that mean that `currentContext` hides the views in the navigation stack while `overFullScreen` still leaves all views appearing but covers them? – Manuel Oct 07 '19 at 00:40
  • 3
    Hmm. If the navigation controller is defining the presentation context, what's the point of using current context or over current context in the first place? Surely the navigation controller is occupying the whole screen, and so this would just be a roundabout way of saying fullscreen or overfullscreen, yes? Current context is useful only in a "small" view controller like a popover or a child. – matt Oct 07 '19 at 01:05
  • Without opening another can of worms, the reason is that there is an underlying controller that can slide-in views. If that controller and its views are covered `fullScreen`, there are some side effects I want to avoid. So `overCurrentContext` works perfectly in my case. – Manuel Oct 07 '19 at 01:18
  • 2
    Well for that very reason then I would agree and would suggest `overCurrentContext`. It sounds like just what you do _not_ want to do is rip the navigation controller's view out of the hierarchy, which is what `currentContext` would do. – matt Oct 07 '19 at 01:22
  • 1
    By the way you can get a full picture of this just by switching to the View Debugger which actually shows you both the view controller hierarchy and the view hierarchy. – matt Oct 07 '19 at 01:23
  • This is awesome – hbtpoprock Mar 04 '21 at 15:43