Saturday, June 4, 2016

Modal Popups on iPhone

The way to achieve the look of a modal popup on the iPhone lies in the settings of the Storyboard Segue from the view controller that will be triggering the popup to the view controller that contains the popup.

I choose Cross Dissolve for the Transition so the popup doesn't slide into view but materializes into view on top instead.

You can do all this in just one view controller but I did it this way to reuse the popup in many view controllers and I like the simplicity of it.

For the modal popup view controller I will sometimes add a blur effect or a view with a lowered alpha property so you can still see the underlying screen a little and then put the content in a smaller size.
Here is an example:

View Hierarchy

If you don't get the right view hierarchy, the transition will be messed up.

Wrong Way

Right Way


Close the Popup

Finally I want the user to be able to touch anywhere off the popup to dismiss it. This can be done by adding a Tap Gesture Recognizer or a button with no text to cover the whole screen below the popup's view.

(Xcode 8)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...