Setting UIModalPresentationStyle for iPhone 6 Plus in landscape?

I want to always present the view controller in a popover on all devices and all orientations. I tried to accomplish this by accepting UIPopoverPresentationControllerDelegate

and installing sourceView

and sourceRect

. The segue in the storyboard is set to "Presence as Popover segue". This works really well for all devices and orientations, except for the iPhone 6 Plus in landscape. In this case, the view controller slides off the bottom of the screen in the form of a sheet. How can I prevent this from always appearing in the popover?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let popoverPresentationController = segue.destinationViewController.popoverPresentationController
    popoverPresentationController?.delegate = self
    popoverPresentationController?.sourceView = self.titleLabel!.superview
    popoverPresentationController?.sourceRect = self.titleLabel!.frame
}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

      

+3


source to share


1 answer


Implement new method (iOS 8.3) adaptivePresentationStyleForPresentationController:traitCollection:

UIAdaptivePresentationControllerDelegate

:

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
    // This method is called in iOS 8.3 or later regardless of trait collection, in which case use the original presentation style (UIModalPresentationNone signals no adaptation)
    return UIModalPresentationNone;
}

      



UIModalPresentationNone

tells the presentation controller to use the original presentation style, which in your case the popover will render.

+7


source







All Articles