I have an app (supported interface orientation - portrait only) with the next hierarchy of modally presented view controllers:

```
A -> B -> AVP

```

Where A is a view controller sitting in tab bar controller, tab bar controller is in turn root of window.

B is a rather simple view controller with button, image and labels but presented as a popup:

```
// ... presentation method in A
let B = // create B
B.modalPresentationStyle = .popover
B.preferredContentSize = CGSize(width: 300, height: 400)
B.isModalInPopover = true
if let BPopover = B.popoverPresentationController {
    BPopover.delegate = self
    BPopover.permittedArrowDirections = []
    let window = // grab current window
    BPopover.sourceView = window
    BPopover.sourceRect = window.bounds
    BPopover.passthroughViews = nil
}
self.tabBarController?.present(B, animated: true, completion: nil)

```

AVP is a AVPlayerViewController presented from B:

```
// This method is in B.
@IBAction func playVideoButtonPressed(_ sender: Any) {
    if let videoURL = self.videoURL {
        let videoPlayer = AVPlayer(url: videoURL)
        let videoVC = AVPlayerViewController()
        videoVC.player = videoPlayer
        self.present(videoVC, animated: true, completion: nil)
    }
}

```

On iOS 10.0 I have an issue if I perform next steps: 

1. present AVP.
2. rotate device so AVP rotates video in horizontal orientation
3. I dismiss AVP in horizontal orientation (using its system provided controls)

When I come back, my view controller B is messed up - moved to the top of window and it size is smaller (also messed up inside, but I guess insides are messed up as a result of my autolayout constraints).

This doesn't seem to happen on iOS 11.

Is there anything I could do to fix it?

EDIT: Screenshots as requested (tabbar was hidden for privacy reasons):

[![Normal state of popup](https://i.stack.imgur.com/rewHw.png)](https://i.stack.imgur.com/rewHw.png) [![Popup after video player](https://i.stack.imgur.com/ycOB9.png)](https://i.stack.imgur.com/ycOB9.png) 

Additional info:

I have also intercepted a delegate callback for more info:

```
func popoverPresentationController(_ popoverPresentationController: UIPopoverPresentationController,
                                   willRepositionPopoverTo rect: UnsafeMutablePointer<CGRect>,
                                   in view: AutoreleasingUnsafeMutablePointer<UIView>) {
    print("willRepositionPopoverTo")
    print(popoverPresentationController)
    print(rect.pointee)
    print(view.pointee)
}

```

Which prints `view` size as `(w: 568; h: 320)` so it seems when I rotate AVP controller it changes my app's window orientation and this leads to resizing of my popup. Although it doesn't attempt to resize it back :( after I dismiss AVP.