我在使用iOS 6 SDK时遇到了这个问题:我有一些视图应该被允许旋转(例如,一个视频视图),而另一些则不应该。 现在我明白了我必须检查应用程序的 Info.plist 中的所有方向,然后在每个ViewController中进行筛选,决定应该发生什么。但它并没有起作用!应用程序总是旋转到在Info.plist中给出的方向。
Info.plist:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
任何不应该被允许旋转的视图控制器:
//deprecated
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
观察:应用程序在横向和纵向方向上旋转。有什么想法或我做错了什么吗?
谢谢,马克
编辑:我的最新发现也表明,如果您想在应用程序中某个时刻进行旋转,则必须在项目设置或Info.plist中激活所有四个旋转方向。另一种选择是覆盖。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
在您的AppDelegate中,它覆盖了Info.plist。 现在不再可能仅在Info.plist中设置Portrait,然后通过覆盖shouldAutorotateToInterfaceOrientation或supportedInterfaceOrientations在某些ViewController中进行旋转。