5

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

我的应用程序将导航控制器作为根视图控制器。这个导航控制器有标签控制器。选项卡控制器有一些视图控制器。我希望第一个视图控制器(在选项卡控制器中)仅以纵向模式查看,而第二个视图控制器(在选项卡控制器中)同时查看纵向和横向模式。它在 iOS5 中可以正常工作。但我不知道如何在iOS6中制作它。虽然我知道我应该继承supportedInterfaceOrientations,但它在旋转发生时不起作用。令我惊讶的是,它在视图显示时被调用。如何做出我想要的?

感谢您的阅读。

4

3 回答 3

8

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

基本上,您需要继承 UINavigationController 并让它监听-supportedInterfaceOrientationstopViewController. 您可以在博客文章中下载一个示例类,并解释要添加的代码。

于 2012-10-01T07:52:39.990 回答
0

当您使用 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 类似。

于 2012-10-01T13:07:40.657 回答
0

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

也许用谷歌英文翻译很有意义

于 2012-10-03T11:37:04.513 回答