0
votes

I've followed various tutorials and downloaded multiple versions of custom UINavigationController custom transition animation examples:

And what I've written and what I've downloaded all suffer from the same problem. After presenting a new view controller, if I rotate the device and then navigate back, none of the previous view controllers in the stack have been rotated. It feels like by using the custom animation I've removed the view controller from the UINavigationControllers child controllers and so it doesn't send any of the rotation messages that it receives on down.

Has anyone run into this? Am I, and all of these other people doing something wrong? Or is this an un-intended consequence of custom transition animations with UINavigationControllers?

I've tested on device and simulator with the same results.

After writing none above it made me think what would happen if one of my transitions wasn't custom, so I tested that and the non-custom animated transition doesn't have this issue, the view controller transitioned from still gets rotation message appropriately. So this issue is specifically tied to using a custom transition animation.

1
Found this post in the developer forums: forums.developer.apple.com/thread/11612 The proposed fix works, but is very hackyRob Booth

1 Answers

0
votes

I don't have an actual answer because this appears to be an actual Apple Bug. From this forum a radar has been filed and a hack to fix the problem was shown. Here is what I did:

First I added this extension to UIViewController to set the top view in my current view hierarchy to have it's frame match the UIWindows frame, effectively rotating the view.

extension UIViewController {
    func rotateTopView(view:UIView) {
        if let superview = view.superview {
            rotateTopView(view: superview)
        } else {
            view.frame = UIWindow().frame
        }
    }
}

Second I added a call to my new rotateTopView method in my viewWillAppear method of the viewControllers that were affected:

override func viewWillAppear(_ animated: Bool) {        
    // Hack to fix rotation issues
    self.rotateTopView(view: view)
}

Hopefully Apple will fix the rotation after custom animation issue soon, but given the original radar was submitted in 2015 I'm not holding my breath.