简体   繁体   English

启用iPhone界面方向

[英]Enable iPhone Interface Orientation

I'm trying to get my application to rotate the interface when the device itself is rotated, but I can't get it right. 我试图让我的应用程序在设备本身旋转时旋转界面,但我无法做到正确。 I have added the supported interfaces in the plist info file and returned yes for the shouldRotateToInterfaceOrientation. 我在plist info文件中添加了支持的接口,并为shouldRotateToInterfaceOrientation返回yes。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
        return YES;  
    } else {  
        return NO;  
    }  
}

Is this how rotation is implemented? 这是如何实现轮换的?
Please help! 请帮忙!

Maybe try editing the info.plist and also add your supported orientations there? 也许尝试编辑info.plist并在那里添加您支持的方向?

Select your project --> Select your target --> Info --> Supported interface orientations and click on the plus sign 4 times to support these orientations: 选择项目 - >选择目标 - >信息 - >支持的界面方向,然后单击加号4次以支持这些方向:

Item 0   Landscape (left home button)
Item 1   Landscape (right home button)
Item 2   Portrait (top home button)
Item 3   Portrait (bottom home button)

Hope it helps! 希望能帮助到你!

Make sure you've added shouldRotateToInterfaceOrientation to the view controllers that you want to support different orientations. 确保已将shouldRotateToInterfaceOrientation添加到要支持不同方向的视图控制器。 It doesn't go in the app delegate. 它不会进入app委托。

Supporting orientation is straight-forward if you're using standard UI elements so, assuming that's the case, you're on the right track. 如果您使用标准UI元素,支持方向是直截了当的,因此,假设情况如此,您就是在正确的轨道上。

If you're using a UITabController, all the views must support the same orientations, otherwise it defaults to the minimum (eg Portrait), I believe. 如果您正在使用UITabController,则所有视图必须支持相同的方向,否则默认为最小(例如Portrait),我相信。

Also, if you're using NIBs for your views, make sure you have 'Autoresize subviews' checked when configuring the view in Interface Builder. 此外,如果您正在为视图使用NIB,请确保在Interface Builder中配置视图时选中了“自动调整子视图”。

if you are using UITabBarController , then you'll need to call it's subviews' shouldAutoratateToInterfaceOrientation . 如果你正在使用UITabBarController ,那么你需要调用它的子视图' shouldAutoratateToInterfaceOrientation

suppose you have two tabs, please try to add the following two lines to method shouldAutorotateToInterfaceOrientation in the class that uses the UITabViewController . 假设你有两个选项卡,请尝试以下两行方法添加shouldAutorotateToInterfaceOrientation在使用该类UITabViewController

[[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation];

of course the "tabBarController" must be linked to the UITabBarController in your XIB file via IB. 当然“tabBarController”必须通过IB链接到XIB文件中的UITabBarController

Thanks, 谢谢,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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