简体   繁体   中英

When the user changes device orientation, how to rotate only the navigation bar and not the view?

So, basically I have a ViewController with a navigation bar at the top.

Say, for the sake of the example, my ViewController's view is a picture from the number 8. What can I do so when the device rotates, the navigation bar rotates as well and stays at the top, but the 8 is exactly the same as before, making it now look like the infinity symbol ? (since the device was rotated but the picture is not, the 8 is now "laying down").

Thanks

edited: ok, got it.

had to implement willRotateToInterfaceOrientation, to rotate the view 90 degrees before the orientation changes, also had to adjust the view's bounds

Have you tried doing this?

RootViewController: where you have alloc init your navigation controller. Allow here to rotate device (shouldautorotatetointerfaceorientation - YES)

But in childViewController: where you don't want to allow to change orienation. There also implement the same method, return NO.

I am not sure about this whether it will work or not. But its just a suggestion.

You could begin by looking at UIViewControllers willRotateToInterfaceOrientation:duration:

From here you could invoke actions before the view controller rotates, like setting the view frame differently

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM