如何仅在iPhone应用程序上支持肖像模式
我正在开发的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);
}
我注意到刚才,当我旋转手机,我得到这个消息:
“两级旋转动画被弃用此应用程序应该 使用更流畅的单段动画。“
这是什么意思?
它可以在屏幕上有多个ViewControllers。 UITabBarController
本身就是一个UIViewController
,如果它选择的话,它只传递shouldAutorotateToInterfaceOrientation:
请求给viewControllers。默认实现是这样做的,但是如果你继承它的话,XCode生成的代码(从iOS 5.1开始)不会。
转到info.plist文件。右键单击打开它作为源代码。并寻找这条线。对我来说,在iPad上它是这样的:
<key>UISupportedInterfaceOrientations~ipad</key>
删除所有其它的方向,并保持你need..Like这个只有一个:
<array>
<string> UIInterfaceOrientationPortrait </string>
</array>
谢谢,但我已经做到了 – Eyal 2012-04-06 10:47:33
然后你的问题很奇怪。 – 2012-04-06 10:48:08
从每个地方返回NO。 – Nilesh 2012-04-05 18:13:17
试试我的答案。也许它会有所帮助。 – 2012-04-06 10:45:15
试着在你的'shouldAutorotateToInterfaceOrientation'方法中添加'NSLog(@“检查方向%d”,interfaceOrientation);''。当您旋转模拟器或您的设备时是否调用了它们中的任何一个? – Dondragmer 2012-04-07 22:48:42