我无法理解iOS6中的旋转机制

问题描述:

我的应用程序具有视图控制器子类shouldautorotateToInterfaceOrientation。其中,我决定每个视图的旋转。这工作正常。但在iOS6中,尽管我阅读了提供给Apple的文档,但我无法理解它。我无法理解iOS6中的旋转机制

我的应用程序具有导航控制器作为根视图控制器。此导航控制器有选项卡控制器。而选项卡控制器有一些视图控制器。我希望第一个视图控制器(在选项卡控制器中)仅作为肖像模式查看,而第二个视图控制器(在选项卡控制器中)查看纵向和横向模式。它在iOS5中正常工作。 但我不知道如何使它在iOS6中。虽然我知道我应该支持子类supportedInterfaceOrientations,但它在旋转发生时不起作用。令我惊讶的是,当一个视图正在显示时被调用。 如何制作我想要的?

谢谢您的阅读。

+0

你应该定义你的应用程序所支持的定向' - 应用:supportedInterfaceOrientationsForWindow:在'AppDelegate.m'文件'或在'Info.plist'和你如果您的视图支持或不支持预定义的方向,视图将只响应具有BOOL值的'-sharedAutorotate:'方法。 ' - shouldAutorotateToInterfaceOrientation:'在iOS6中已被弃用。 – holex

+0

谢谢holex。我解决了它。 – eon

以下链接可能引导你正确的方向:http://code.shabz.co/post/32051014482/ios-6-supportedorientations-with-uinavigationcontroller

基本上,你需要继承UINavigationController的,并有其听变化,其topViewController-supportedInterfaceOrientations。您可以在博客文章中下载示例课程,并解释要添加的代码。

+1

谢谢。我解决了它。 – eon

当您使用的UINavigationController或UITabbarViewController - 应用程序始终做他们在shouldAutorotate说什么,supportedInterfaceOrientations方法。

您可以为它们添加一个类别,将这些方法重定向到它们当前显示的控制器。 赞:

@implementation UINavigationController (Rotation_IOS6) 
-(BOOL)shouldAutorotate 
{ 
    return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 
@end 

与UITabbarViewController类似。

+0

这可能会产生意想不到的副作用。想想看,如果你这么做的话,那么这就是系统范围内的所有导航控制器的行为,即使它们是由操作系统提供的。因为这个,我得到了一个崩溃。继承是更好的,因为你仍然控制谁获得特殊行为,谁不能。 – n13

在我看来,这是我发现的最好的解释:http://www.widemann.net/wp-fr/?p=662但它是法文的。

也许是有意义与谷歌traduction in english