I am presenting a view controller modally with its UIModalPresentationStyle
set to the adaptive style UIModalPresentationPopover
. This style when in a horizontally compact environment (iPhone portrait) will appear over the full screen. When in a horizontally regular and vertically compact environment (iPhone 6 Plus landscape) it will appear in a form sheet. And when in a regular regular environment (iPad) it will appear as a popover. This is the desired behavior.
I need to programmatically determine how that controller will actually be displayed - form sheet, over full screen, or popover. How can I determine that from within the view controller that is being presented?
The reason is I need to add a Done button only in the case it is not within a popover. (Or hide it in the case it is in a popover.)
Creating the view controller:
let viewController = ...
viewController.modalPresentationStyle = .Popover
let popoverController = viewController.popoverPresentationController
popoverController?.barButtonItem = settingsButton
presentViewController(viewController, animated: true, completion: nil)
Inside the viewController:
- (void)viewDidLoad {
[super viewDidLoad];
//self.modalPresentationStyle is Popover even in the case where it's presented over the full screen
//self.popoverPresentationController is not nil even when presented full screen
}