简体   繁体   English

当用户更改设备方向时,如何仅旋转导航栏而不旋转视图?

[英]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.

相关问题 当设备方向改变时如何旋转视图以保持正确的窗口大小 - how to rotate view when device orientation changes keeping the correct size of window iOS-设备旋转时是否只能旋转导航栏按钮? - iOS - Is it possible to only rotate navigation bar buttons when device rotates? 如何使uiviews仅在方向更改时旋转(变换)? - how to make uiviews only rotate (transform) when orientation changes? 设备方向更改时调整PDF查看大小 - Resize PDF View when device orientation changes 设备方向更改时,自定义UIView不会旋转 - Custom UIView does not rotate when device orientation changes 设备方向更改时,UIWebview中出现黑条 - Black bar appearing in UIWebview when device orientation changes 当应用程序只有一个方向时如何旋转UIImage的方向 - How to rotate orientation of UIImage when application have only one orientation 当iPhone / iPad的设备方向改变时,如何处理UI组件? - How to handle UI components when device orientation for iPhone/iPad changes? 当导航栏的颜色在不同的View Controller中变化时,如何更改后退按钮的颜色? - How to change the colour of the back button when the colour of the navigation bar changes across different View Controllers? 如何只允许导航堆栈中的一个视图旋转? - How to allow only one view in navigation stack to rotate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM