[英]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. 因此,基本上,我有一个ViewController,顶部带有导航栏。
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 ? 举例来说,我的ViewController的视图是数字8的图片。当设备旋转时,导航栏也旋转并停留在顶部,但是8与以前,使其现在看起来像无穷大符号? (since the device was rotated but the picture is not, the 8 is now "laying down").
(由于设备已旋转,但图片未旋转,所以8现在正在“放下”)。
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 必须实现willRotateToInterfaceOrientation,在方向更改之前将视图旋转90度,还必须调整视图的边界
Have you tried doing this? 您是否尝试过这样做?
RootViewController: where you have alloc init your navigation controller. RootViewController:您在其中分配初始化导航控制器的位置。 Allow here to rotate device (shouldautorotatetointerfaceorientation - YES)
在这里允许旋转设备(应该自动旋转到界面方向-是)
But in childViewController: where you don't want to allow to change orienation. 但是在childViewController中:您不想允许更改方向的位置。 There also implement the same method, return NO.
这里也实现了相同的方法,返回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:
您可以先查看UIViewControllers
willRotateToInterfaceOrientation:duration:
From here you could invoke actions before the view controller rotates, like setting the view frame differently 在这里,您可以在视图控制器旋转之前调用动作,例如以不同方式设置视图框架
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.