首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS 6旋转问题-无法从显示的模式视图控制器旋转

iOS 6旋转问题-无法从显示的模式视图控制器旋转
EN

Stack Overflow用户
提问于 2012-09-24 00:50:45
回答 4查看 24.4K关注 0票数 16

我有一个MainViewController,它有一个按钮,可以通过水平翻转来推动新的视图(InfoViewController)。如下所示:

代码语言:javascript
复制
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];

MainView控制器支持纵向和PortraitUpsideDown。如下所示:

代码语言:javascript
复制
- (BOOL)shouldAutorotate {
    return YES;    
}

- (NSUInteger)supportedInterfaceOrientations {    
    return (UIInterfaceOrientationMaskPortrait | 
            UIInterfaceOrientationMaskPortraitUpsideDown);
}

在我的InfoViewController中,它还说明了上面的代码。在我的AppDelegate中,它在LaunchOptions中包含以下内容:

代码语言:javascript
复制
[self.window setRootViewController:self.mainViewController];

在我的app.plist文件中,它支持所有方向。这是因为其他视图也需要支持景观。所以在我的MainViewController和InfoViewController上,我只需要画像和PortraitUpsideDown。但从另一个角度来看,我需要所有的想法。

我的MainViewController运行良好,但我的InfoViewController适用于所有方向。

我在iOS6中尝试让它工作时遇到了极大的困难。我也研究过其他帖子,尝试过其他人提供的帮助,但都没有任何收获。有人能帮我拿一下这个吗?谢谢。我是Objective-C新手:p

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-09-24 02:47:14

不要在你的应用plist文件中支持所有的方向,只支持你的根视图控制器支持的方向。

在iOS 6中,自动旋转发生了变化。在iOS 6中,不推荐使用UIViewController的shouldAutorotateToInterfaceOrientation:方法。取而代之的是,您应该使用supportedInterfaceOrientationsForWindow:shouldAutorotate方法:

代码语言:javascript
复制
- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;    
}

在iOS 6中,Modal ViewControllers不再获得旋转调用:不再在任何在其自身上进行全屏呈现的视图控制器上调用willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:,didRotateFromInterfaceOrientation:方法-例如,使用:presentViewController:animated:completion:调用的那些视图控制器。

您可以让呈现您的模式视图控制器的视图控制器通知它旋转。另外,现在使用:presentViewController:animated:completion:来表示视图控制器。presentModalViewController:animated:已弃用,您可以在代码中使用它。

票数 26
EN

Stack Overflow用户

发布于 2012-10-08 08:29:50

在使用标签栏控制器时,我已经解决了类似的问题。

子类UITabBarController。实现以下方法:

代码语言:javascript
复制
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}


- (BOOL)shouldAutorotate
{
    NSLog(@"Orientation:%d", [[UIDevice currentDevice] orientation]);

    for (UIViewController *viewController in self.viewControllers) {
        [viewController shouldAutorotate];
    }

    return YES;
}

如果你想在tabbarcontroller中的控制器中处理旋转,那么在标签栏中的每个控制器中,控制器也要实现这些方法,并编写代码来处理方向的改变。如果你不想处理它,那么你就不需要实现这些方法。当方向改变时,TabBarControllers方法将始终运行。甚至两次也不知道原因。

是的,别忘了删除所有的shouldAutorotate方法。我完全转向了新的定向模型。如果你想让他们留下来,可能会更难。

票数 3
EN

Stack Overflow用户

发布于 2014-03-25 13:51:02

通过对UINavigationController进行子类化来创建一个类别,并在.h文件中实现以下方法

代码语言:javascript
复制
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;



 in .m file

-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}

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

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
return [self.topViewController preferredInterfaceOrientationForPresentation];
 } 

并在视图控制器类中实现以下方法,类u要启用旋转

代码语言:javascript
复制
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |   UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
 }


- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return UIInterfaceOrientationLandscapeLeft;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12554204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档