20

我在用

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

委托根据方向类型更改我的视图框架

IE,

if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
    self.view.frame=CGRectMake(0,0,500,300);
}
else
{
    self.view.frame=CGRectMake(0,0,300,400);
}

如何在 iOS 6 中处理与

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在 iOS6 中已被弃用。

我正在使用以下委托来设置所有方向。

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationAllMask;
}

但,

-(BOOL)shouldAutoRotate
{
    return YES;

}

没有被调用。如何处理这种情况?

在此处输入图像描述

4

7 回答 7

46

在 AppDelegate 中,我已将 ViewController 对象添加到窗口中

[self.window addSubView:viewControllerObj]

问题出在上面的行上。在 iOS 5 中,方向将与上述行正常工作,但在 iOS 中,要使方向正常工作,请将上述行更改为

[self.window setRootViewController:viewControllerObj]

然后当方向改变时应用程序会旋转。

于 2012-09-21T10:55:06.477 回答
3

确保项目和目标中的设置允许每种设备类型的方向。

此外,您拥有的代码shouldAutorotateToInterfaceOrientation:可以放入viewDidLayoutSubviews.

于 2012-09-20T19:39:17.467 回答
1

请记住,在 iOS 6 中,旋转的处理是在父母视图中小心处理的。对子视图控制器的责任较小。但对我们来说更烦人的是没有接口生成器的代码。

于 2012-09-21T10:17:37.923 回答
0

确保您的所有方向都已启用。在此处输入图像描述

于 2012-09-22T11:49:06.030 回答
0

此方法适用于 IOS 6 和旧版本

-(BOOL)rotationChanged:(UIInterfaceOrientation)interfaceOrientation {
    NSInteger 方向 = [[UIDevice currentDevice] 方向];
    UIWindow *_window = [[[UIApplication sharedApplication] delegate] window];
    if ([PGPlatformUtils GetCurrentPlatform]==PGPlatformEnum_iPhone) {
        开关(方向){
            情况1:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait 动画:YES];

                [UIView 提交动画];
                休息;
            案例2:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait 动画:YES];

                [UIView 提交动画];
                休息;
            案例3:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight 动画:YES];

                [UIView 提交动画];
                休息;
            案例4:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (- M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft 动画:YES];

                [UIView 提交动画];
                休息;
            案例5:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIPrintInfoOrientationLandscape 动画:YES];

                [UIView 提交动画];
                休息;


            默认:
                休息;
        }
    }
    别的{
        开关(方向){
            情况1:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait 动画:YES];
                NSLog(@"*** 1 定向调用 0");

                [UIView 提交动画];
                休息;
            案例2:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown 动画:YES];
                NSLog(@"*** 1 定向调用 M_PI");
                [UIView 提交动画];
                休息;
            案例3:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight 动画:YES];
                NSLog(@"*** 1 次定向调用 M_PI/2");
                [UIView 提交动画];
                休息;
            案例4:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (- M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft 动画:YES];
                NSLog(@"*** 1 定向调用 - M_PI/2");
                [UIView 提交动画];
                休息;
            案例5:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.0];

                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 768, 1024)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIPrintInfoOrientationLandscape 动画:YES];
                NSLog(@"*** 1 定向调用 0");
                [UIView 提交动画];
                休息;

            默认:
                休息;
        }
    }
    返回是;

}
于 2013-06-07T08:37:41.807 回答
0

处理 iOS 6 中的 UINavigation 方向问题

1 创建一个 UINavigation+Rotation 类别类

2 在 UINavigation+Rotation.m 类中放置以下方法

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

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([self.viewControllers count] == 0) {
        return UIInterfaceOrientationPortrait;
    }
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
于 2013-03-21T13:04:20.273 回答
0

willAnimateRotationToInterfaceOrientation在 iOS6 中使用。

于 2013-07-05T07:49:47.580 回答