This will be a very basic app which will illustrate different ModalpresentationStyle
in iOS. According to documentation found here, There are 9 different values for UIModalPresentationStyle
which are as follows,
fullScreen
pageSheet
formSheet
currentContext
custom
overFullScreen
overCurrentContext
popover
none
To setup a project, just create a normal iOS project and add 2 ViewControllers
. Put a UIButton
in you initial ViewController
and connect it to 2nd ViewController
via a Target -> Action
mechanism. To distinguish both ViewControllers
, set background property of UIView
in ViewController
some other color. If all goes well, your Interface Builder should look something this,
Make sure you build this project and run it on iPad (For details on why iPad, refer to Remarks section). Once you are done setting up your project, select the segue and go to the attributes inspector
. You should be able to see something like this,
Set the kind property to Present Modally
.
Now, we won’t see all of the effects in this example as some of them requires little bit of code.
Let’s start with fullscreen
. This effect is selected by default when you select Present Modally
in Kind
tab. When you build and run, the 2nd ViewController
would occupy the full screen of you iPad.
Next is pageSheet
. You can select this option from Presentation
tab. In this option, when device is in portrait mode, the 2nd ViewController
is similar to full screen but in landscape mode, 2nd ViewController
is much narrow the device width. Also, any content not covered by 2nd ViewController
will be dimmed.