Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c iOS 6旋转问题-显示的模态视图控制器没有旋转_Objective C_Ios_Ios6 - Fatal编程技术网

Objective c iOS 6旋转问题-显示的模态视图控制器没有旋转

Objective c iOS 6旋转问题-显示的模态视图控制器没有旋转,objective-c,ios,ios6,Objective C,Ios,Ios6,我有一个MainViewController,它有一个按钮,通过水平翻转来推动一个新视图(InfoViewController)。像这样: controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES]; MainView控制器支持纵向和纵向向上向下。像这样: - (BOOL)shouldAutoro

我有一个MainViewController,它有一个按钮,通过水平翻转来推动一个新视图(InfoViewController)。像这样:

controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
MainView控制器支持纵向和纵向向上向下。像这样:

- (BOOL)shouldAutorotate {
    return YES;    
}

- (NSUInteger)supportedInterfaceOrientations {    
    return (UIInterfaceOrientationMaskPortrait | 
            UIInterfaceOrientationMaskPortraitUpsideDown);
}
在我的InfoViewController中,它还声明了上述代码。在my AppDelegate中,它在启动选项中包含以下内容:

[self.window setRootViewController:self.mainViewController];
在my app.plist文件中,它支持所有方向。这是因为其他视图也需要支持景观。因此,在我的MainViewController和InfoViewController上,我只需要纵向和纵向向上向下。但从另一个角度看,我需要所有的方位

我的MainViewController工作正常,但我的InfoViewController适用于所有方向


在iOS6中,我很难让它正常工作。我曾研究过其他帖子,尝试过其他人提供的帮助,但一点运气都没有。请有人帮我做这个谢谢。我是Objective-C新手:p

不支持应用程序plist文件中的所有方向,只支持根视图控制器支持的方向

iOS 6中的自动旋转正在改变。在iOS 6中,UIViewController的
shouldAutorotateToInterfaceOrientation:
方法不受欢迎。取而代之的是,您应该使用
支持的interface orientations for window:
should autorotate
方法:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;    
}
在iOS 6中,模式ViewController不再获得旋转调用:
将旋转接口方向:持续时间:,
WillAnimateRotationInterfaceOrientation:持续时间:,
didRotateFromInterfaceOrientation:
方法不再在任何在上进行全屏演示的视图控制器上调用 本身,例如使用以下命令调用的对象:
presentViewController:animated:completion:

可以让显示模态视图控制器的视图控制器通知其旋转。
另外,现在您可以使用:
presentViewController:animated:completion:
来显示视图控制器
presentModalViewController:animated:
不推荐在代码中使用。

我在使用选项卡栏控制器时解决了类似的问题

子类UITabBarController。实施这些方法:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}


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

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

    return YES;
}
如果要在tabbarcontroller内部的控制器中处理旋转,则在tab bar控制器中的每个控制器中也要实现这些方法,并编写代码来处理方向更改。如果您不想处理它,那么就不需要实现这些方法。方向更改时,TabbarController方法将始终运行。甚至因为未知的原因两次


是的,不要忘记删除所有shouldAutorotate方法。我完全转向了新的定位模式。如果您想让它们保留下来,可能会更难。

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

-(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希望启用旋转

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


- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return UIInterfaceOrientationLandscapeLeft;
}

在子类UITabBarController.m上添加此代码

@implementation UINavigationController (rotation)
//temp hack for iOS6, this allows passing supportedInterfaceOrientations to child viewcontrollers.
- (NSUInteger)supportedInterfaceOrientations {
    return [self.topViewController supportedInterfaceOrientations];
}
@end

@implementation NameClassUITabBar

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

@end
在这里,我将我的解决方案/经验发布在带有旋转的选项卡栏控制器中:

标题中写着“无旋转”。在你倒数第二段,它说它对所有方向都有效。是哪一个?对,好的。我已经从plist中删除了除纵向(主页按钮底部)以外的所有方向。但现在我有了一个观点,它需要所有的方向。我已经将supportedInterfaceOrientations放在列表中,然后列出了所有内容,但它不起作用。谢谢。如果您的shouldAutorotate没有返回YES,那么您的supportedInterfaceOrientations将永远不会被调用,视图也不会旋转。什么是不工作?该视图的shouldAutorotate返回YES。然后返回要允许旋转的supportedInterfaceOrientations。在iOS 6中,模态视图控制器不再接收旋转调用