I'm trying to show a popOver
with a UISlider
inside, to allow an user to control the textSize
of a WKWebView
.
Here is how I did it:
MYCustomViewController *popoverContent = [[self storyboard] instantiateViewControllerWithIdentifier:@"MYCustomViewController"];
popoverContent.delegate = self;
popoverContent.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popover = popoverContent.popoverPresentationController;
popoverContent.preferredContentSize = CGSizeMake(220, 40);
popover.delegate = self;
popover.barButtonItem = (UIBarButtonItem *)sender;
[self presentViewController:popoverContent animated:YES completion:nil];
In the custom ViewController
I just added a delegate to get the value of the UISlider
I also implemented the method:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return UIModalPresentationNone;
}
Everything works just fine on every device except the iPhone 6 Plus in Landscape (i.e. compact height), which displays the popover
as UIPageSheet
Note: I present the popover from a UIbarButtonItem
, in the detailViewController
of a UISplitViewController
I solved this issue by implementing the new adaptivePresentationStyleForPresentationController:traitCollection:
method of UIAdaptivePresentationControllerDelegate:
as suggested by @Joshua
- (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
.