7plus popoverPresentationController:willRepositionPopoverTo

Hello,


I am using popover controllers for all devices and UI traits. According to sources on the internet this how you express to the SDK that you wish to use popovers on all devices. Unfortunately the 7plus (simulater ond device) converts the popover into a partially offscreen modal form sheet on rotation. The expected willRepositionPopoverTo delegate method is not called (nor any pther delegate methods) only on the 7p. All other simuated devices work as expected. I am targetting iOS 10 and iOS9. I have not tried on earlier targets yet.


Any advice or workaround is appreciated


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     segue.destination.modalPresentationStyle = UIModalPresentationStyle.popover
     destination.popoverPresentationController!.delegate = self
}

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
     return UIModalPresentationStyle.none
}

public func popoverPresentationController(_ popoverPresentationController: UIPopoverPresentationController,
     willRepositionPopoverTo rect: UnsafeMutablePointer<CGRect>,
     in view: AutoreleasingUnsafeMutablePointer<UIView>) {
     // Not called for iPhone 7 plus. Popover is transformed into a partially off screen form sheet instead.
}

Figured it out...

This method does get called to see if an adaption should happen!


  func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return UIModalPresentationStyle.none
  }

Thank you. This resolved a problem I was having with my app running on iPhone 7 Plus.


When popover was presented and 7 Plus was rotated to landscape, I was unable to dismiss popover until rotating 7 Plus back to portrait. Originally, I had a tableview as one of the popovers and I used viewWillTransition func to dismiss TVC if device was anything but portrait. However; I added a feature that was a view controller with a StackView(to include two SegmentControls) to show as a popover. When rotated, my StackView was in the center with the rest of the view(white background) covering the vertical bounds, then it would dismiss. Or as you stated, "converts the popover into a partially offscreen modal form sheet on rotation".


Implementing func adaptivePresentationStyle(.., traitCollection: UITraitCollection...) resolved: 1. modal presentation, and 2. ugly UI

7plus popoverPresentationController:willRepositionPopoverTo
 
 
Q