【问题标题】:Rotation Code not working in iOS6 it worked perfectly on iOS 5旋转代码在 iOS6 中不起作用它在 iOS 5 上完美运行
【发布时间】:2012-12-16 09:15:56
【问题描述】:

我有这段代码,它在 iOS 5 上完美运行,但在 iOS 6 上不能运行,请帮助

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
    {
        return (orientation != UIDeviceOrientationPortrait) &&
        (orientation != UIDeviceOrientationPortraitUpsideDown);
    }

【问题讨论】:

标签: iphone objective-c xcode ios5 ios6


【解决方案1】:

让我们试试这个: 首先在viewDidLoad函数里面使用这个代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}

然后,我将创建将接收两行代码通知的函数:

- (void)orientationChanged:(NSNotification *)object{
    NSLog(@"orientation change");
    UIDeviceOrientation deviceOrientation = [[object object] orientation];
    if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        if(deviceOrientation ==UIInterfaceOrientationPortrait){
            NSLog(@"Changed Orientation To Portrait");
            // Handle your view.
        }
    }else{
        if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
            NSLog(@"Changed Orientation To Landscape left");
            // Handle your view.
        }else{
            NSLog(@"Changed Orientation To Landscape right");
            // Handle your view.
        }

    }
}

我希望我的回答会有所帮助。干杯。

【讨论】:

    【解决方案2】:

    在 iOS6 中,“shouldAutorotateToInterfaceOrientation”方法已被弃用。尝试在 plist 文件中设置方向。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多