shouldAutorotateToInterfaceOrientation:从来没有调用

我将“支持的界面方向”设置为“部署信息”下除“人像”之外的所有人物。

我想重写shouldAutorotateToInterfaceOrientation:用于自定义行为。 (即根据条件支持景观)

我只有一个视图控制器由于约束(自定义视图转换)

这就是我的appdelegate中的代码:

self.viewController = [[MyController alloc]initWithNibName:nil bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; 

并在myController.m,我重写shouldAutorotateToInterfaceOrientation:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return YES; } 

应用程序自动转向所有的方向,但倒像和callback从来没有被调用。 我已经尝试了从shouldAutorotateToInterfaceOrientation更改返回的build议:在runTime没有成功。 为什么?

在附注中,在运行时更改旋转支持的最佳方法是什么?

更新:

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

被调用。 我试过放进去

 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; 

没有成功:(

正在使用ios6

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 

已在ios6上弃用

它为我工作:

 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { NSUInteger orientations = UIInterfaceOrientationMaskPortrait; if ([self isKindOfClass:[YourViewController class]]) { // Your view class orientations |= UIInterfaceOrientationMaskPortraitUpsideDown; } return orientations; } 

方向:

 orientations |= UIInterfaceOrientationMaskLandscapeLeft; orientations |= UIInterfaceOrientationMaskLandscapeRight;