Implementing a popover
A popover is a transient view that appears above other content onscreen when you tap a control area. Popovers typically include an arrow pointing to the location from where it emerged and are dismissed by tapping another part of the screen or a button on the popover.
Popovers are typically used on larger screens and can contain a wide variety of elements. Anything from navigation bars, tables collections, or any other views. The Apple Human Interface guidelines recommend using popovers on iPads only and not iPhones.
In this recipe, we will create a simple popover with a text and display it on an iPad.
Getting ready
Create a new SwiftUI app named PopoverApp
.
How to do it
Following the pattern we've used so far in this chapter, we shall first create an @State
variable whose value triggers the displaying or hiding of a popover, and then add a .popover()
modifier that displays the popover when the @State
variable is true
. The steps are as...