UIPopover object manages the display of content in a popover. From the time a popover is presented until the time it is dismissed, UIKit uses an instance of this class to manage the presentation behavior. You use instances of this class as-is to configure aspects of the popover appearance and behavior for view controllers whose presentation style is set to
- iOS 8.0+
In nearly all cases, you use this class as-is and do not create instances of it directly. UIKit creates an instance of this class automatically when you present a view controller using the
popover style. You can retrieve that instance from the presented view controller’s
popover property and use it to configure the popover behavior.
If you do not want to configure a popover immediately after presenting a view controller, you can use a delegate object to configure the popover instead. During the presentation process, the popover presentation controller calls various methods of its delegate—an object that conforms to the
UIPopover protocol—to ask for information and to inform it about the state of the presentation. Your delegate object can use those methods to configure the popover and adjust its behavior as needed. For information about how to implement a delegate for a popover presentation controller, see
Configuring a Popover for Display
To display a popover, set the presentation style of your view controller to
popover and call the
present(_: method. Presenting a view controller with the popover style creates a popover presentation controller to manage the presentation process. You can retrieve that presentation controller from the presented view controller’s
popover property and use the object to configure the popover behavior.
Listing 1 shows an example of how you present a view controller using the popover style. After setting the style and calling the
present(_: method, you can fetch the presentation controller and modify its properties. When configuring popovers, always specify either a bar button item or a source view and rectangle as the anchor point for the popover. You can configure other properties as well to accommodate the presented content.
Configuring the popover presentation controller after calling
present(_: might seem counter-intuitive but UIKit does not create a presentation controller until after you initiate a presentation. In addition, UIKit must wait until the next update cycle to display new content onscreen anyway. That delay gives you time to configure the presentation controller for your popover.