Lesson 20

Popovers and Modal Views

Popovers and modal views provide ways to temporarily display some information to users. The information that is displayed is usually contextual and related to an action performed by the user.

Both popovers and modal views interrupt the user's journey through your application; the user must interact with the popover/modal view before using the rest of the application. Popovers are dismissed by tapping outside the bounds of the popover; modal views are dismissed by using a user-defined cancel button located in the modal view. Popovers are only available on iPads, whereas modal views are available on both the iPad and iPhone.

Popovers

A popover view is one that is revealed when a control is tapped. A popover appears attached to the control that was tapped to reveal it (see Figure 20.1).

Screenshot of iOS device with a flower with yellow petals, with a box on left bottom, with the Height (pixels) set to 451.0, Width (pixels) set to 676.0, and Colorspace set to RGB.

Figure 20.1

Popovers are only supported on the iPad, and should be used to display additional information related to the control that displays it. When presenting a popover, you do not provide a Done or Cancel button; popovers are dismissed when the user taps outside the popover.

To present a scene in your storyboard in a popover, simply create a popover presentation segue from a button in one of the other scenes of your view controller to the scene you wish to use within the popover (see Figure 20.2).

Figure 20.2

You can use the Attribute inspector ...

Get Swift iOS 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.