UINavigationController and autorotation

后端 未结 7 1596
灰色年华
灰色年华 2020-12-13 19:46

I have a UIViewController that returns YES in shouldAutorotateToInterfaceOrientation: for UIDeviceOrientationPortrait and NO

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 20:01

    I was about to tell you that there was probably no way, but then I had a thought. It would be difficult to get right, but you might be able to make it work if you used two separate UINavigationControllers: one that controls the root view and prohibits rotation, and one for the child views that allows it. You would manually handle the transition to and from the root controller and the child controller.

    You'd have to patch up the child navigation controller to have the correct back button. And, of course, you'd have to handle the back button press yourself. You would probably have to use a dummy UINavigationBar to do the animation from one navigation controller to the next so that the transition will look right. You would also have to animate the "push" transition between the navigation controllers, as well, which might take a bit of tweaking to get it to look right. You would have to:

    1. Configure a dummy navigation bar to exactly match the outgoing navigation controller's and place it directly on top of the navigation controller's bar. (You could copy the configuration of the current view controller's UINavigationItem and push it on)
    2. Place the new navigation controller off-screen at the right edge
    3. Animate the movement of the new and old controllers' frames from right to left
    4. Create a copy of the UINavigationItem for the incoming view controller and push it on the dummy navigation bar
    5. When the animation completes, remove the dummy UINavigationBar from the view, and also the outgoing navigation controller.

    All of this is a lot of work, but if you're very clever (and very tenacious), you might be able to get it to work. I'd love to see the result!

    That said, you might be better off just using setOrientation: and taking your chances with the App Store approval process ;-)

提交回复
热议问题