我有一个带有 Storyboard的 iOS 应用程序。我希望我的最后一个 View Controller 始终保持纵向模式。我一直在阅读,我发现自从
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
已弃用我应该使用其他方法,例如
-(BOOL)shouldAutorotate
-(NSInteger)supportedInterfaceOrientations
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
但是我已经尝试了很多这种方法的组合,但我还是做不到。那么有人可以告诉我正确的方法吗?
最佳答案
由于您的 UIViewController 嵌入在 UINavigationController 中,除非您自己转发调用,否则它永远不会被调用。 (我认为 UINavigationController 有点缺陷)
像这样子类化 UINavigationController:
@interface RotationAwareNavigationController : UINavigationController
@end
@implementation RotationAwareNavigationController
-(NSUInteger)supportedInterfaceOrientations {
UIViewController *top = self.topViewController;
return top.supportedInterfaceOrientations;
}
-(BOOL)shouldAutorotate {
UIViewController *top = self.topViewController;
return [top shouldAutorotate];
}
@end
关于ios - 如何强制 View Controller 保持纵向模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16720968/