ios 6应用程序正在旋转,即使使用shouldAutorotate:NO

Fry*_*Fry 6 objective-c rotation ios6

因为iOS6我的旋转问题很大.我实现了所有新的旋转方法(shouldAutorotate,preferredInterfaceOrientationForPresentation,supportedInterfaceOrientation),但所有视图仍在旋转.有趣的是,视图保持其大小,窗口的其余部分(在风景中)是黑色的.

这就是我实现它的方式,有什么不对吗?

#pragma mark -
#pragma mark - InterfaceOrientation iOS 5 
//Deprecated in iOS 6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark - InterfaceOrientation iOS 6

- (BOOL)shouldAutorotate{
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)

谢谢你们的帮助.

Fry*_*Fry 9

我通过为navigationcontroller创建一个类别来解决问题:

@implementation UINavigationController (iOS6fix)

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

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end
Run Code Online (Sandbox Code Playgroud)

感谢大家的答案!