处理iPhone方向横向/纵向 [英] Handle iPhone orientation Landscape/Portrait

查看:84
本文介绍了处理iPhone方向横向/纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,它具有多个不同的视图控制器.一个登录屏幕,然后是包含表视图的其他三个视图控制器.我使用的是情节提要,而不是NIB文件,并且已在情节提要中纵向设计每个视图.当我运行我的应用程序时,当我打开设备时,登录屏幕会在横向/纵向之间切换,看起来还不错.但是,其他屏幕不会改变...嗯,实际上它们会从横向更改为纵向,但不会从纵向更改为横向.如果我在登录视图上,请导航至其他视图,以横向查看它们,但是一旦我转动设备并将其切换为纵向视图,它就会卡住,直到我返回登录屏幕为止.

I have an iPhone app that has several different view controllers. A login screen and then three other view controllers that contain table views. I am using the storyboard, not NIB files, and have designed each view in a portrait orientation on the storyboard. When I run my app, the login screen switches between landscape/portrait when I turn the device and looks just fine. However, the other screens do not change...well, actually they WILL change from landscape to portrait, but they won't change from portrait to landscape. If I am on the login view, then navigate to the other views I can see them in landscape, but as soon as I turn the device and it switches to portrait, it's stuck until I go back to the login screen.

我已经搜索并找到了涉及NIB文件的答案,但是与使用情节提要板时如何使用设备方向无关.我是否缺少一些要在视图上设置的属性?如何使表格视图像登录视图一样工作并自动自动切换方向?

I've searched and found answers that involve NIB files, but nothing about how to work with the device orientation when using the storyboard. Am I missing some property to set on the view? How can I get my table views to work like my login view and automatically switch the orientation automatically?

推荐答案

如果要在代码中锁定视图方向,可以使用以下方法锁定它:

If you want to lock the view orientation in code you lock it with this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

这篇关于处理iPhone方向横向/纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆