我想在一个ViewController中禁用屏幕旋转。我用这个来改变屏幕方向为纵向:ObjC禁用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;
}
,但它不工作。它将屏幕旋转为纵向,但不会锁定它,如果我打开设备,它会改变屏幕方向。
请访问我的答案[这里](http://stackoverflow.com/questions/34655338/how-can-i-rotate-a-uiviewcontroller-to-its-supported-interface-orientation-when/ 34655782#34655782) – Aamir
它不起作用... – klh63917
你可能错过了一些东西,我测试过这段代码,它对我来说工作正常。 – Aamir