1

I have this code and it works perfectly on iOS 5 but not on iOS 6 please help

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

2 回答 2

2

让我们试试这个:首先内部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.
        }

    }
}

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

于 2012-12-16T13:41:26.983 回答
1

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

于 2012-12-16T09:26:17.867 回答