【发布时间】:2016-01-10 18:49:37
【问题描述】:
我试图在一个 ViewController 中禁用屏幕旋转。我正在使用它来将屏幕方向更改为纵向:
-(void)viewDidAppear:(BOOL)animated{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
我正在像这样禁用旋转:
- (BOOL)shouldAutorotate{
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController {
return navigationController.topViewController.supportedInterfaceOrientations;
}
但它不起作用。它将屏幕旋转为纵向,但不会锁定它,如果我转动设备,它会改变屏幕方向。
【问题讨论】:
-
请访问我的回答here
-
你可能会遗漏一些东西,我已经测试了这段代码,它对我来说工作正常。
标签: objective-c