Why isn't preferredContentSize used by iPhone 6 Plus Landscape?
What you're seeing is not a popover. It's a normal presented view. By default, a popover appears as a popover on iPad, but as a presented view on iPhone — including the iPhone 6 plus. On other iPhones, this presented view is fullscreen - it covers everything. But the iPhone 6 is so wide that they don't do that, so it appears in the middle of the screen at a standard width (the width of a smaller iPhone).
Thus, the preferred content size has no effect. This isn't a popover. Presented view controller views are given a standard size, and this one is no exception.
However, you can have the popover appear as a popover on iPhone. To do so:
Set a delegate for the popover view controller's
popoverPresentationController
before presenting it.In the delegate, implement
adaptivePresentationStyleForPresentationController:
and return.None
.
However, this is apparently not working on iPhone 6 Plus in landscape mode; the popover is not "adapting". I would describe this as a bug!
EDIT In iOS 9, the problem is solved! Implement the new delegate method adaptivePresentationStyleForPresentationController:traitCollection:
to return .None
and you'll get a popover under all circumstances, including the iPhone 6 Plus in landscape. Here's a complete working example where the popover is created and summoned in code in response to a button tap:
@IBAction func doButton(sender: AnyObject) {
let vc = MyViewController()
vc.preferredContentSize = CGSizeMake(400,500)
vc.modalPresentationStyle = .Popover
if let pres = vc.presentationController {
pres.delegate = self
}
self.presentViewController(vc, animated: true, completion: nil)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
}
}
func adaptivePresentationStyleForPresentationController(
controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .None
}
Swift 2.0 Popover view cannot get proper location on iPhone 6s plus but it works fine on iPhone 6s
I found the solution on internet and it should add this function to handle iPhone plus case.
func adaptivePresentationStyleForPresentationController(
controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .None
}
For the detail, please check this link.
Why isn't preferredContentSize used by iPhone 6 Plus Landscape?
UIModalPresentationPopover for iPhone 6 Plus in landscape doesn't display popover
Implement the new adaptivePresentationStyleForPresentationController:traitCollection:
method of 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 will display a popover.
Setting UIModalPresentationStyle for iPhone 6 Plus in landscape?
Implement the new (as of iOS 8.3) adaptivePresentationStyleForPresentationController:traitCollection:
method of 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 will display a popover.
Why splitViewController:collapseSecondaryViewController:ontoPrimaryViewController: is not called on iPhone 6 Plus?
iPhone 6+ has a larger screen and in some ways is treated like an iPad. A split view controller on an iPhone 6+ will try to display both master and detail panes similarly as on an iPad, unless the application is in "Zoomed Display Mode".
NSHipster has an article explaining this in greater detail: http://nshipster.com/uisplitviewcontroller/
Segue to popover for iPhone not working in iOS 10?
Many function have been renamed in Swift 3, including adaptivePresentationStyleForPresentationController
- this is now adaptivePresentationStyle(for:)
Change your code to
func adaptivePresentationStyle(for controller:UIPresentationController) -> UIModalPresentationStyle {
return .none
}
Since your function name didn't match it wasn't being called and because it is an optional function in the protocol, you didn't get a warning.
Popover presentation on an iPhone using UIPopoverPresentationController
Here's your problem:
[self presentViewController:popupController animated:YES completion:nil];
popupPresentationController= [popupController popoverPresentationController];
popupPresentationController.delegate = self;
That code is in the wrong order. You must set the delegate
before calling presentViewController
.
Related Topics
How to Use Afnetworking or Sthttprequest to Make a Request of a Soap Web Service
Detect If iOS App Is Downloaded from Apple's Testflight
Facebook App Invites Notification Not Working in iOS
Custom Font on Uibutton Title Clipped on Top of Word
Send Image Along with Other Parameters with Afnetworking
Xcode Logging: "Metal API Validation Enabled"
Admob Sdk - iOS -File Not Found
Perform Action by Clicking on Some Word in Uitextview or Uilabel
How to Get the iPhone Type from Simulator (Ios)
Prepare(For Segue: Uistoryboardsegue, Sender: Anyobject) Missing in Swift 3.0/Xcode 8 B6
Adjusting Uiview Height Inside Uistackview Control
How to Update Data in Tableview Without the Delay Using Cloudkit When Creating New Records
Swift: Change Status Bar Color for iOS 13
Expected Declaration Error Creating Array in Viewcontroller, Can't Work Out Why
Incorrect Height Calculation with Draggesture() in Swiftui
Uiimagepickercontroller in Swift 3
How to Programmatically Get iOS's Alphanumeric Version String