Image for post
Image for post
Startup photo depicting startup things.

iPhone X: Dealing with Home Indicator

New APIs from Cupertino & Friends™

Jordan Morgan
Sep 13, 2017 · 7 min read

A quick note — all of my future posts will be published on my dedicated website and this publication is no longer being updated. Thanks for reading!

But First

It’s not everyday we get new videos alongside a hardware announcement, and yet that’s exactly what happened shortly thereafter:

  • Don’t hide the indicator, add any adornments around it or generally attempt to change its appearance. Same goes for the camera bezel that’s planted at the top of iPhone X.
  • Typically you don’t want to hide the home indicator unless you’ve got a passive viewing experience (i.e. videos, photo slideshow, etc.).

UIViewController Additions

Whether you adore handling the status bar on a per controller basis or it was pure anathema to you, Apple has continued the trend of making such decisions on an instance by instance basis rather than opting for a global catch all design.

class ViewController: UIViewController
{
override func prefersHomeIndicatorAutoHidden() -> Bool
{
return true
}
}

Signaling UIKit

Continuing with the status bar API parallels, simply overriding, or assigning to a variable conditionally controlling the overriden function, is not enough. We’ve yet another new addition to view controller’s robust family of setNeedsSomethingDone functions:

class ViewController: UIViewController
{
var shouldHideHomeIndicator = false
override func prefersHomeIndicatorAutoHidden() -> Bool
{
return shouldHideHomeIndicator
}
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
self.shouldHideHomeIndicator = true
self.setNeedsUpdateOfHomeIndicatorAutoHidden()
}
}
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.shouldHideHomeIndicator = true
UIView.animate(withDuration: 1, animations: {
self.setNeedsUpdateOfHomeIndicatorAutoHidden()
})
}
}

Container Controllers

The last new addition to view controller is a mechanism to inform UIKit if a child view controller should dictate home indicator’s visibility or not. If you’ve been around iOS long enough, you’ve likely harnessed container view controllers to better promote abstractions and encapsulation patterns.

override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController?
{
return myChildController
}
class MyChildViewController: UIViewController
{
override func prefersHomeIndicatorAutoHidden() -> Bool
{
return true
}
}
override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController?
{
return myChildController
}
func initializeChildController()
{
myChildController = MyChildController()
self.setNeedsUpdateOfHomeIndicatorAutoHidden()
}

Update: Answers to Reader Questions

Fabian Kuenzel asks:

<meta name='viewport' content='initial-scale=1, viewport-fit=auto'>
.post {
padding: 12px;
padding-left: constant(safe-area-inset-left);
padding-right: constant(safe-area-inset-right);
}
override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
return .top
}

Wrapping Up

Ah, iPhone X considerations.

The Traveled iOS Developer’s Guide

Cocoa Touch, unwrapped and analyzed by @JordanMorgan10.

Jordan Morgan

Written by

iOS @buffer. Author for Pluralsight, contributor to a few books, conference talks and some other stuff! Writing at swiftjectivec.com

The Traveled iOS Developer’s Guide

Cocoa Touch, unwrapped and analyzed by @JordanMorgan10. Updated biweekly.

Jordan Morgan

Written by

iOS @buffer. Author for Pluralsight, contributor to a few books, conference talks and some other stuff! Writing at swiftjectivec.com

The Traveled iOS Developer’s Guide

Cocoa Touch, unwrapped and analyzed by @JordanMorgan10. Updated biweekly.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store