[英]How to lock rotation orientation for portrait in objective c
我是iOS的新手,我面临着关于轮换的问题。 我只需要纵向锁定单视图控制器旋转。 我正在使用这样的代码
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:NO];
[UIView setAnimationsEnabled:NO];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
这在风景中工作得很好,但在肖像中却没有。我怎么能用它来画像。 我试过像这样的肖像方法。
仅使用此代码纵向视图控制器,在IOS 9或更高版本上测试。
//锁定纵向方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
-(NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController {
return UIInterfaceOrientationMaskPortrait;
}
要么
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate {
return NO;
}
检查一下( iOS 6 shouldAutorotate:未被调用 )答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.