Sye*_*man 3 iphone objective-c uiviewcontroller uiinterfaceorientation ios
我的应用程序支持所有4方向,我有一个UIViewController这是LandscapeRight.我正在使用UINavigationController推动它UIViewController,我希望它UIViewController只是在UIInterfaceOrientationLandscapeRight,但当我旋转手机时,它切换回其他方向.
-(BOOL)shouldAutorotate{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationLandscapeRight;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)
只需删除那些shouldAutorotate,supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation.
并将此添加到您想要仅显示横向的viewcontroller.
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
forKey:@"orientation"];
}
Run Code Online (Sandbox Code Playgroud)
实际上,这是来自类似问题的解决方案. 如何在iOS 8中强制查看控制器方向?
| 归档时间: |
|
| 查看次数: |
8496 次 |
| 最近记录: |