如何使界面方向自动旋转为纵向?

时间:2012-10-03 13:45:25

标签: iphone ios xcode cocoa

我正在尝试将我的一个xib文件旋转为纵向,就像它首先是默认值一样。

我让我的应用程序仅支持横向方向。在plist我设置了“初始界面方向到横向(右主页按钮)”,因为大多数应用程序在横向模式下运行。

我在实施文件中的代码是:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

现在当更改为需要界面处于纵向模式的视图控制器时,我已将此代码放在xib文件的实现文件中,使其进入纵向模式并仅支持纵向模式。因此即使设备处于横向模式,它仍然会以纵向模式运行视图。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortrait;

}

虽然这似乎不起作用。它只是保持横向模式并挤压图像视图和我放在xib文件中的其他对象。如何让xib旋转到纵向模式?感谢。

3 个答案:

答案 0 :(得分:0)

尝试使用这些链接(link1 link2)可以帮助您。

答案 1 :(得分:0)

  change your Xib in Landscape Mode only and then click on your project file then target   then select only Landscape mode or Portrait Mode(left/right or both) 
  then go to this method 
I am using Landscape Mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  // Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

enter image description here

答案 2 :(得分:0)

我的经验表明,在plist文件中设置UIInterfaceOrientation没有任何效果。另一方面,您可以通过设置:

在启动时强制方向(例如横向)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    // your stuff
{

您也可以稍后使用此方法强制设备的逻辑方向。注意:从this document

开始,这是Apple的“官方”方法
相关问题