在 appDelegate 中:
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
带有方法的特殊 UINavigationController 子类(如果您使用导航控制器):
- (NSUInteger)supportedInterfaceOrientations {
if (self.topViewController.presentedViewController) {
return self.topViewController.presentedViewController.supportedInterfaceOrientations;
}
return self.topViewController.supportedInterfaceOrientations;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return self.topViewController.preferredInterfaceOrientationForPresentation;
}
每个视图控制器都应该返回它自己支持的方向和首选的呈现方向:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
我的应用程序以纵向模式工作,但视频播放器以模态 vc 的形式打开:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
它对我来说很完美,希望对我有帮助!