Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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
iOS6定向_Ios_Orientation_Landscape_Ios6_Portrait - Fatal编程技术网

iOS6定向

iOS6定向,ios,orientation,landscape,ios6,portrait,Ios,Orientation,Landscape,Ios6,Portrait,我有一个关于iOS 6定位的问题。这是我的文件 在这个示例代码中,我想使MasterViewController仅具有纵向方向,而DetailViewController具有纵向方向和横向方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientation

我有一个关于iOS 6定位的问题。这是我的文件

在这个示例代码中,我想使
MasterViewController
仅具有纵向方向,而
DetailViewController
具有纵向方向和横向方向

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate {
    return FALSE;
}
我知道iOS 6的方向是由最顶端的控制器控制的

因此,我定制了一个
UINavigationController(CustomNavigationController)
,设置了支持的接口方向,并应在该类中自动旋转

-(NSUInteger)supportedInterfaceOrientations{
    if([[self topViewController] isKindOfClass:[DetailViewController class]]){
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

-(BOOL)shouldAutorotate
{
    return YES;
}
一切正常,除了在横向方向按下后退按钮时,
DetailViewController
将显示横向方向

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate {
    return FALSE;
}
我是否可以让
MasterViewController
始终显示纵向,并且
DetailViewController
可以有多个方向


谢谢

我是按照你在对这个问题的评论中提出的建议来做这项工作的。问题在于默认的UINavigatonController不使用俯视图控制器的值,因此需要通过创建基类并在情节提要中将其设置为基类来覆盖它

下面是我使用的代码

- (NSUInteger) supportedInterfaceOrientations {
    return [self.topViewController supportedInterfaceOrientations];
}
我还有一个基类,用于视图控制器的其余部分,以默认使用纵向方向的行为。我可以在任何支持纵向以上方向的视图控制器中覆盖iOS 5和iOS 6的这些方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate {
    return FALSE;
}

我按照你在对这个问题的评论中的建议做了这项工作。问题在于默认的UINavigatonController不使用俯视图控制器的值,因此需要通过创建基类并在情节提要中将其设置为基类来覆盖它

下面是我使用的代码

- (NSUInteger) supportedInterfaceOrientations {
    return [self.topViewController supportedInterfaceOrientations];
}
我还有一个基类,用于视图控制器的其余部分,以默认使用纵向方向的行为。我可以在任何支持纵向以上方向的视图控制器中覆盖iOS 5和iOS 6的这些方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate {
    return FALSE;
}
谢谢!布伦南,
我也在我的博客中收集其他人这样做的方式。

这是另外两条路

1.向UINavigationController添加类别

    @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
2.Swap方法实现(由spoletto制作)

谢谢!布伦南,
我也在我的博客中收集其他人这样做的方式。

这是另外两条路

1.向UINavigationController添加类别

    @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
2.Swap方法实现(由spoletto制作)


我今天找到了解决办法。在CustomNavigationController-(NSUInteger)supportedInterfaceOrientations{return[[self-topViewController]supportedInterfaceOrientations];}中设置此选项,然后在MasterViewController-(NSUInteger)supportedInterfaceOrientations{return UIInterfaceOrientationMaskPortrait;}上设置此选项,如果找到问题的答案,你应该把你的答案贴出来作为答案,并标记为正确,没关系。我今天找到了解决办法。在CustomNavigationController-(NSUInteger)supportedInterfaceOrientations{return[[self-topViewController]supportedInterfaceOrientations];}中设置此选项,然后在MasterViewController-(NSUInteger)supportedInterfaceOrientations{return UIInterfaceOrientationMaskPortrait;}上设置此选项,如果找到问题的答案,你应该将你的答案作为答案发布,并标记为正确,没关系。投票吧,因为阅读你的帖子让我最终解决了我遇到的ios6设备旋转问题。我希望我的应用程序只能是人像,但演示全屏视频时除外。我的解决方案是在info.plist中将支持的方向设置为纵向,覆盖tab bar子类以返回纵向方向/纵向方向掩码/自动旋转编号。这是有效的,因为tab bar是父视图控制器!谢谢。向上投票,因为读了你的帖子,我终于解决了我遇到的ios6设备旋转问题。我希望我的应用程序只能是人像,但演示全屏视频时除外。我的解决方案是在info.plist中将支持的方向设置为纵向,覆盖tab bar子类以返回纵向方向/纵向方向掩码/自动旋转编号。这是有效的,因为tab bar是父视图控制器!谢谢