我将新方法添加到我的代码中,如苹果iOS 6 Documentations中描述的那样,但在iPhone 5上,应用程序不会颠倒过来。只有景观方式。
这里是来自rootViewController的代码:
- (NSUInteger)supportedInterfaceOrientations{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
- (BOOL)shouldAutorotate{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
return YES;
}
我也试过“UIInterfaceOrientationMaskAll”但没有变化。奇怪的是,我的带有iOS6的iPhone 4使用相同的代码完全颠倒了o。
任何想法?
答案 0 :(得分:61)
IOS 6使用iPad的默认方位UIInterfaceOrientationMaskAll
和iPhone的UIInterfaceOrientationMaskAllButUpsideDown
。如果您希望iPhone上的ViewControllers旋转到包括UpsideDown在内的所有方向,您必须添加iOS 6方法:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
到所有视图控制器。如果你已经完成了这个并且它没有工作,那么我打赌你使用TabViewController或NavigationController,其中一些视图没有返回这个。所有ViewControllers都必须为它们中的任何一个返回它以支持它。
或者,您可以将类别添加到作为rootViewController的UITabViewController或NavigationController类并覆盖该方法。你是这样做的:
@interface UITabBarController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations;
@end
@implementation UITabBarController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
@end
这些是Apple开发人员论坛中目前正在讨论的目前推荐的方法,Apple工作人员说早期的文档不鼓励对UINavigationController进行子类化已经过时了,从iOS 6开始就可以这样做。
答案 1 :(得分:12)
感谢Cliff Ribaudo真正帮助您完成基于UITabbarController的项目的答案,但在我的情况下,我只使用UINavigationController,所以我修改了UINavigationController categeory的答案。
@interface UINavigationController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations;
@end
@implementation UINavigationController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
@end
答案 2 :(得分:0)
原谅冗长,但我认为你的答案如下。
我遇到了同样的问题,但它发生在所有IOS 6设备上,包括我的iphone 4.阅读你的问题实际上回答了我的问题。我之前删除了它,因为它没有做任何事情:
- (NSUInteger)supportedInterfaceOrientations{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown); }
我的代码在之前的ios版本中完美运行。看来这已经成为ios 6中的强制要求。但仅限于upsideDown。其他方向运作良好。
所以,谢谢你。
回到你的问题。您是否已查看项目目标以查看所有“支持的接口方向”是否为深灰色?我想知道颠倒是否是浅灰色(即未经检查)。我在快速测试中发现,在之前的ios版本中,这些也被忽略了。只要你从shouldAutorotateToInterfaceOrientation返回YES,它就会支持方向,但不支持iOS 6。
最后,您已经实现了shouldAutorotate,我没有在我的代码中。我认为这默认为是。我认为这只是告诉操作系统尝试旋转,但是你必须告诉它你支持哪些方向shouldAutorotateToInterfaceOrientation。但是您的代码段并未显示您已实现了shouldAutorotateToInterfaceOrientation。我建议实现这个,因为它告诉操作系统你支持哪些方向返回一个简单的YES意味着你支持所有。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
希望这有帮助。
答案 3 :(得分:0)
默认目标设置没有倒置方向,请尝试以下方法:
转到项目文件 选择您的应用目标 选择“Summery”选项卡 检查所有方向类型是否按下
祝你好运:)答案 4 :(得分:0)
如果您计划为所有视图控制器启用或禁用旋转,则不需要继承UINavigationController。 而是使用:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
在你的AppDelegate中。
如果您计划支持应用中的所有方向,但PARENT视图控制器(例如UINavigationController堆栈)的方向不同,则应使用
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
来自AppDelegate的与PARENT视图控制器中的以下方法结合使用。
- (BOOL)shouldAutorotate
和
- (NSUInteger)supportedInterfaceOrientations
但是如果您计划在同一个导航堆栈(例如我)中的不同CHILDREN ViewControllers中使用不同的方向设置,则需要检查导航堆栈中的当前ViewController。
我在UINavigationController子类中创建了以下内容:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
int interfaceOrientation = 0;
if (self.viewControllers.count > 0)
{
id viewController;
DLog(@"%@", self.viewControllers);
for (viewController in self.viewControllers)
{
if ([viewController isKindOfClass:([InitialUseViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else if ([viewController isKindOfClass:([MainViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else
{
interfaceOrientation = UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return interfaceOrientation;
}
由于您无法再控制子视图控制器所呈现的视图控制器的旋转设置,您必须以某种方式拦截视图控制器当前在导航堆栈中的内容。这就是我做的:)。希望有所帮助!