0

I present a popover programmatically from a button on toolbar. I successfully implemented it on Xcode 8.1.

            _myMapViewController.modalPresentationStyle = UIModalPresentationPopover;

            switch ([[UIApplication sharedApplication] statusBarOrientation]) {
                case UIInterfaceOrientationPortrait:
                case UIInterfaceOrientationPortraitUpsideDown:
                    // Resize Popover
                    _myMapViewController.preferredContentSize = self.popoverSizeForPortrait;
                    break;
                case UIInterfaceOrientationLandscapeLeft:
                case UIInterfaceOrientationLandscapeRight:
                    // Resize Popover
                    _myMapViewController.preferredContentSize = self.popoverSizeForLandscape;
                    break;
                default:
                    //do nothing
                    break;
            }

            UIPopoverPresentationController *popoverPresentation = _myMapViewController.popoverPresentationController;
            [popoverPresentation setBarButtonItem:_mapButton];
            [popoverPresentation setPermittedArrowDirections:UIPopoverArrowDirectionDown];
            [popoverPresentation setDelegate:self];

            [self presentViewController:_myMapViewController animated:YES completion:nil];

Below is a successful outcome on iPhone 7. You see a popover of a map anchored to compass button on the bottom left. iPhone 7 simulator in landscape

However, when I run the same code with iPhone 6 Plus and 7 Plus simulators, the popover in landscape mode is shown from unknown (and unintended) anchor) like this: enter image description here

Showing the popover in portrait mode has no issues. Any idea for resolution would be appreciated.

tsuyoski
  • 614
  • 5
  • 22
  • There's no bug. On iPhone 6/7 plus in landscape, it's _not_ a popover. That is deliberate, normal, default behavior. But you can override that behavior and _make_ it a popover if you want to. – matt Nov 27 '16 at 18:03
  • Yes, I was able to resolve by reading: http://stackoverflow.com/questions/31275151/why-isnt-preferredcontentsize-used-by-iphone-6-plus-landscape – tsuyoski Nov 27 '16 at 18:14
  • I had - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { return UIModalPresentationNone; } But not this. -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection { return UIModalPresentationNone; // this is necessary to make iPhone plus to behave as popover } As soon as I added the second one, 6 plus and 7 plus work as I want. Thanks! – tsuyoski Nov 27 '16 at 18:16
  • Excellent! Glad you got it working. – matt Nov 27 '16 at 20:00

0 Answers0