2012-08-27 148 views
0

我不知道为什么设备方向不起作用。设备方向

在项目属性:

enter image description here

在我的代码有:

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

我探讨它在我的iPhone,并不会改变。

有什么缺失?

预先感谢您

编辑(info.plist中)

enter image description here

+0

支持的界面方向添加info.plist – Rajneesh071

+1

您的设备上是否启用了方向锁? –

+0

不,它没有被锁定,我也尝试过在xcode中使用iphone模拟器 – user1256477

回答

0

打开info.plist文件XCode,并添加一行 - 类型的数组Supported interface orientation

点击它旁边的加号按钮,列出所有想要使用的方向。 您可以为iPhoneiPad设置不同的设置。

+2

如上图所示选择支持的方向时,会自动完成此操作。 –

+0

使用此信息编辑我的帖子 – user1256477

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

return NO; 

} 
+1

这与OP的代码在语义上相同。 –

+1

好吧,我的错误... – NightCoder

0

你的代码在哪里是shouldAutorotateToInterfaceOrientation:执行?它应该是UIViewController的每个子类的一种方法。

尝试通过在shouldAutorotateToInterfaceOrientation:中放入日志语句或断点来确保它正在工作。如果没有被调用,其他地方的视图控制器正在为您决定有效的方向。

+0

我试着你说的NSLog,该方法被称为,但它不会改变 – user1256477