【问题标题】:device orientation设备方向
【发布时间】:2012-08-28 14:23:53
【问题描述】:

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

在项目属性中:

在我的代码中:

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

我在我的 iphone 中探测它并没有改变。

有什么遗漏吗?

提前谢谢你

已编辑(info.plist)

【问题讨论】:

  • 在 info.plist 中添加支持的界面方向
  • 您的设备是否启用了方向锁定?
  • 不,它没有被锁定,我也试过用xcode中的iphone模拟器
  • 您是否使用自定义初始化程序在代码中初始化视图控制器?您是否覆盖了-initWithNibName:bundle:?您的视图控制器是嵌入在父视图控制器中的子视图控制器吗?

标签: iphone objective-c xcode4.3


【解决方案1】:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if((interfaceOrientation == UIInterfaceOrientationPortrait) ||
   (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)||
   (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
    return YES;
}

return NO;

}

【讨论】:

    【解决方案2】:

    在您的代码中,shouldAutorotateToInterfaceOrientation: 是在哪里实现的?它应该是UIViewController 的每个子类的方法。

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

    【讨论】:

    • 我用NSLog试了你说的,方法调用了,但是没变
    【解决方案3】:

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

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

    【讨论】:

    • 如上图所示,当您选择支持的方向时,此操作会自动完成。
    猜你喜欢
    • 2013-10-10
    • 2018-09-20
    • 2019-05-18
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多