Does anyone know if UIPopoverPresentationController
can be used to present popovers on iPhones? Wondering if Apple added this feature on iOS 8 in their attempt to create a more unified presentation controllers for iPad and iPhone.
Not sure if its OK to ask/answer questions from Beta. I will remove it in that case.
You can override the default adaptive behaviour (
UIModalPresentationFullScreen
in compact horizontal environment, i.e. iPhone) using theadaptivePresentationStyleForPresentationController:
method available throughUIPopoverPresentationController.delegate
.UIPresentationController
uses this method to ask the new presentation style to use, which in your case, simply returningUIModalPresentationNone
will cause theUIPopoverPresentationController
to render as a popover instead of fullscreen.Here's an example of the popover using a segue setup in storyboard from a
UIBarButtonItem
to "present modally" aUIViewController
This trick was mentioned in WWDC 2014 session 214 "View Controller Advancement in iOS8" (36:30)
Make sure to implement UIAdaptivePresentationControllerDelegate
like this:
If you don't want full-screen popovers
In iOS 8.3 and later, use the following syntax in the
UIPopoverPresentationControllerDelegate
protocol to override your popup'sUIModalPresentationStyle
.add these two methods in your WEBVIEW class. and add
If anybody wants to present a popover with code only, you can use the following approach.
OBJECTIVE - C
Declare a property of
UIPopoverPresentationController
:Use the following method to present the popover from UIButton:
Use the following method to present the popover from UIBarButtonItem:
Implement this delegate method too in your view controller:
To dismiss this popover, simply dismiss the view controller. Below is the code to dismiss the view controller:
SWIFT
Use the following method to present the popover from UIButon:
Use the following method to present the popover from UIBarButtonItem:
Implement this delegate method too in your view controller:
Please make sure to add delegate
UIPopoverPresentationControllerDelegate
in .h/.m/.swift fileI've found some workaround.
On Xcode6.1, use
presentationController.delegate
instead ofpopoverPresentationController.delegate
.In WWDC 2014 "View Controller Advancements in iOS8", below codes can show popover on iPhone.
But On Xcode 6.1, these codes shows FullScreen presentation... (nvc.popoverPresentationController is nil)
I doubt it might be an Apple's bug.