Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.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
Ios UIViewController不旋转到横向_Ios_Uiviewcontroller_Ios4 - Fatal编程技术网

Ios UIViewController不旋转到横向

Ios UIViewController不旋转到横向,ios,uiviewcontroller,ios4,Ios,Uiviewcontroller,Ios4,在许多情况下,需要旋转控制器,但控制器不工作。 现在我有了问题的反面:它是旋转的,我想禁用它 在该ViewController中,我有以下内容: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UI

在许多情况下,需要旋转控制器,但控制器不工作。 现在我有了问题的反面:它是旋转的,我想禁用它

在该ViewController中,我有以下内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
但它是自动旋转的,因为请求的不是这个UIViewController,而是它在UI树中的父级。也许这就是问题所在根控制器在所有情况下都必须返回Yes,因为堆栈上还有一些其他UIViewController,它们具有/必须具有Portait/横向支持。

我不能/不想碰其他部分,因为。。。有几个原因,例如:这个应用程序很大,有很多已知的bug,我不想在一周内测试它,另一个原因是最后期限

请不要建议它不应该是这样,必须重写。我知道

如何处理这个控制器来强制移植呢


也请阅读粗体文本:无法强制整个应用程序仅支持Portait for 1 view controller,堆栈上有很多

尝试在属性文件中将应用程序支持的界面方向标记为仅为纵向。当然,在该函数中,您只需在希望允许旋转的视图控制器上返回YES。但是当你把它推回堆栈时,其他视图应该是纵向的


尝试在属性文件中将应用程序支持的界面方向标记为仅为纵向。当然,在该函数中,您只需在希望允许旋转的视图控制器上返回YES。但是当你把它推回堆栈时,其他视图应该是纵向的


检测横向旋转,并旋转至:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{ 

    UIInterfaceOrientation appOrientation = [UIApplication sharedApplication].statusBarOrientation;
    float width = self.view.bounds.size.width;
    float height = self.view.bounds.size.height;
    //NSLog(@"width %3.0f, height: %3.0f", width, height);

    if((fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
        // if is rotated from Portait:
        if((appOrientation == UIInterfaceOrientationLandscapeLeft || appOrientation == UIInterfaceOrientationLandscapeRight)){
            // to Landscape:
            CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, -(M_PI / 2.0));
            self.view.transform = transform;            

            [self.view setBounds:CGRectMake(0, 0, height, width)];
        }
    }
    else {
        // it is rotated from Landscape:
        if((appOrientation == UIInterfaceOrientationPortrait || appOrientation == UIInterfaceOrientationPortraitUpsideDown)){
            // to Portrait:            
            CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, +(M_PI / 2.0));
            self.view.transform = transform;            

            [self.view setBounds:CGRectMake(0, 0, height, width)];
        }
    } 
}
这不是最好的编程范例,但它确实做到了


有人写了类似的东西来接受他的答案,或者写一个更好的方法,如果可以的话

检测横向旋转,并旋转至:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{ 

    UIInterfaceOrientation appOrientation = [UIApplication sharedApplication].statusBarOrientation;
    float width = self.view.bounds.size.width;
    float height = self.view.bounds.size.height;
    //NSLog(@"width %3.0f, height: %3.0f", width, height);

    if((fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
        // if is rotated from Portait:
        if((appOrientation == UIInterfaceOrientationLandscapeLeft || appOrientation == UIInterfaceOrientationLandscapeRight)){
            // to Landscape:
            CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, -(M_PI / 2.0));
            self.view.transform = transform;            

            [self.view setBounds:CGRectMake(0, 0, height, width)];
        }
    }
    else {
        // it is rotated from Landscape:
        if((appOrientation == UIInterfaceOrientationPortrait || appOrientation == UIInterfaceOrientationPortraitUpsideDown)){
            // to Portrait:            
            CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, +(M_PI / 2.0));
            self.view.transform = transform;            

            [self.view setBounds:CGRectMake(0, 0, height, width)];
        }
    } 
}
这不是最好的编程范例,但它确实做到了



有人写了类似的东西来接受他的答案,或者写一个更好的方法,如果可以的话

堆栈上的所有视图控制器必须返回
YES
,以响应
shouldAutorotateToInterfaceOrientation:
,才能正常工作。它们将返回YES。它们在旋转,这很好,只是最后一个元素我想被修复。是的,对不起。请看eric的回答,这不好,除此之外,它建议在应用程序级别进行更改,我真的不希望这样。您是否已将不可旋转的视图控制器注册为正在旋转的根视图控制器的子级?如果回答“否”,则根视图控制器也应回答“否”。堆栈上的所有视图控制器都必须返回
YES
,以响应
shouldAutorotateToInterfaceOrientation:
,才能正常工作。它们返回的是。它们在旋转,这很好,只是最后一个元素我想被修复。是的,对不起。请看eric的回答,这不好,除此之外,它建议在应用程序级别进行更改,我真的不希望这样。您是否已将不可旋转的视图控制器注册为正在旋转的根视图控制器的子级?如果您回答“否”,根视图控制器也应该回答“否”,我告诉它必须支持所有方向:“根控制器必须在所有情况下返回“是”,因为堆栈上还有一些其他UIViewController,它们具有/必须具有Portait/横向支持。”告诉我更改为仅支持portait是没有用的整个应用程序在根视图控制器和每个要旋转的VC中都有它:-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{返回是;}尝试:浪费时间,有趣的是,你看到它不起作用,值得投反对票,而他仍然得到了更多的选票:)我是想帮助你。所建议的任何解决方案都不会完全奏效。这都是关于尝试和错误。很抱歉,我的解决方案对您“不起作用”,但它可能对其他人有用。这至少有助于其他试图回答您的问题的人知道“我的选项”不适用于您特定版本的问题。我告诉它必须支持所有方向:“根控制器在所有情况下都必须返回“是”,因为堆栈上还有其他几个UIViewController,它们具有/必须具有Portait/横向支持。”告诉我更改为仅支持portait是没有用的整个应用程序在根视图控制器和每个要旋转的VC中都有它:-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{返回是;}尝试:浪费时间,有趣的是,你看到它不起作用,值得投反对票,而他仍然得到了更多的选票:)我是想帮助你。所建议的任何解决方案都不会完全奏效。这都是关于尝试和错误。很抱歉,我的解决方案对您“不起作用”,但它可能对其他人有用。这至少有助于其他试图回答你的问题的人知道我的选择不适用于你的问题的特定版本。