2012-04-05 126 views
3

我正在开发的iPhone应用程序中有一个奇怪的问题。我希望我的应用程序仅支持纵向模式,但由于某种原因,我无法执行此操作(设备&模拟器)。如何仅在iPhone应用程序上支持肖像模式

只支持纵向模式我做了如下:

  • 在上Xcode中TARGET摘要部分,我只选择了肖像。
  • 我所有的ViewControllers实现shouldAutorotateToInterfaceOrientation

但正如我所说,它不会工作,而奇怪的结果是,应用程序的支持ALL的方向(纵向,上下颠倒,景观左,右景观) 。
任何想法?

这个我如何实现shouldAutorotateToInterfaceOrientation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    NSLog(@"Checking orientation %d", interfaceOrientation); 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

我注意到刚才,当我旋转手机,我得到这个消息:

“两级旋转动画被弃用此应用程序应该 使用更流畅的单段动画。“

这是什么意思?

+0

从每个地方返回NO。 – Nilesh 2012-04-05 18:13:17

+0

试试我的答案。也许它会有所帮助。 – 2012-04-06 10:45:15

+0

试着在你的'shouldAutorotateToInterfaceOrientation'方法中添加'NSLog(@“检查方向%d”,interfaceOrientation);''。当您旋转模拟器或您的设备时是否调用了它们中的任何一个? – Dondragmer 2012-04-07 22:48:42

回答

3

它可以在屏幕上有多个ViewControllers。 UITabBarController本身就是一个UIViewController,如果它选择的话,它只传递shouldAutorotateToInterfaceOrientation:请求给viewControllers。默认实现是这样做的,但是如果你继承它的话,XCode生成的代码(从iOS 5.1开始)不会。

9

在目标摘要上仅选择肖像。

+1

正如我写的,我已经这样做:( – Eyal 2012-04-05 16:40:28

+0

尝试删除shouldAutorotateToInterfaceOrientation方法,并保持目标设置正确。 – Eric 2012-04-05 16:43:19

+0

抱歉不起作用 – Eyal 2012-04-05 16:53:03

1

检查你的plist并确保钥匙设置正确。

+0

我检查,它被设置为肖像... – Eyal 2012-04-05 16:41:21

3

转到info.plist文件。右键单击打开它作为源代码。并寻找这条线。对我来说,在iPad上它是这样的:

<key>UISupportedInterfaceOrientations~ipad</key> 

删除所有其它的方向,并保持你need..Like这个只有一个:

<array> 

    <string> UIInterfaceOrientationPortrait </string> 

</array> 
+0

谢谢,但我已经做到了 – Eyal 2012-04-06 10:47:33

+0

然后你的问题很奇怪。 – 2012-04-06 10:48:08

相关问题