Topics

#310: Screen Edges in iOS 11 πŸ“²

Topics

Continuing our look at the new tidbits and goodies from WWDC 2017, today we'll learn about the changes to screen edge behavior in iOS 11. Let's dive in.

What we're really talking about here is the behavior when a user drags from offscreen. This could be the user trying to pull down Notification Center from the top, or bring up Control Center from the bottom of the screen.

In past iOS releases, the system has looked at the visibility of the status bar to determine how to behave in these cases.

If we configured one of our view controllers to hide the status bar, the system would show a little "tab" UI with an arrow that the user would need to drag a second time before Notification Center or Control Center would be shown:

Keying off of the visibility of the status bar probably isn't the best way for us to "tell" the system what to do here.

In iOS 11, we've been given a wonderful new way to describe how our app should behave when the user performs these gestures.

Now, all we need to do is override this function in our view controlller:

override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
  return .bottom
}

This way, we can describe exactly which edges of the screen we'd like to allow the system gestures to behave "normally", and which we'd like to have defer for a second drag. Neat!

Finally, if the state of our view controller ever changes enough to warrant a change in this behavior, we can call the following new function to update it:

setNeedsUpdateOfScreenEdgesDeferringSystemGestures()