强制旋转 TabbarController 中 NavigationController 中的 UIViewController
我的视图层次结构是这样设置的。
UITabBarController
|
UINavigationController
| |
| UIViewController
|
UINavigationController
|
UIViewController
问题是,我有一个仅以纵向显示的 ViewController,一旦我将设备转向横向,另一个 ViewController 就会被推到顶部,到目前为止,它正在按预期工作。
我现在想要的是,一旦我按下新弹出的 ViewController 上的后退按钮,旧的 ViewController 就会被强制为纵向,即使设备仍处于横向状态。
我已经尝试过使用过渡,但是其他视图都被搞砸了,并且无法正确识别那里的方向,从而导致混乱的移位视图。
I've got my View hierarchy set up like this.
UITabBarController
|
UINavigationController
| |
| UIViewController
|
UINavigationController
|
UIViewController
The thing is that I have a ViewController that is only shown in Portrait, as soon as I turn the device to landscape another ViewController is being pushed on top, that is working as intended so far.
What I want now is that as soon as I push the back button on the newly popped ViewController that the old ViewController is being forced to Portrait, even though the Device is still in Landscape.
I have tried it with transitions, but then the other views are getting screwed and don't properly recognize there orientation anymore leading to a mess of displaced views.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
唯一对我有用的是
在我的 ViewController 中使用并用 presentModalViewController 呈现它。
这迫使视图保持横向。
不完全是我想要的,但它成功了。
The only thing that worked for me was using
in my ViewController and presenting it with presentModalViewController.
This forces the View to stay in landscape.
Not exactly what I wanted, but it worked out.
尝试将其添加到您的原始视图控制器:
这应该强制它仅以纵向显示。
Try adding this to your original view controller:
This should force it to only display in portrait orientation.
下面的代码将强制视图进入横向模式,但前提是父视图控制器支持横向模式。
如果您想要强制进入横向模式的视图的父视图控制器仅为纵向,则必须创建一个新的导航控制器。最简单的方法就是在模态视图中呈现强制横向视图控制器。所以使用presentModalViewController而不是pushViewController。
The code below will force the view into landscape mode, but only if the parent view controller supports landscape mode.
If the parent view controller of the view you want to force into landscape mode is portrait only, you'll have to create a new new navigation controller. The easiest way to do that is just presenting the forced-landscape view controller in a modal view. So use presentModalViewController instead of pushViewController.