繁体   English   中英

如何锁定目标c中的纵向旋转方向

[英]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"];
} 

这在风景中工作得很好,但在肖像中却没有。我怎么能用它来画像​​。 我试过像这样的肖像方法。

  1. UIInterfaceOrientationMaskPortrait
  2. UIInterfaceOrientationPortrait
  3. UIInterfaceOrientationPortraitUpsideDown
  4. UIInterfaceOrientationMaskPortraitUpsideDown但对我来说都没有用。 提前致谢!

仅使用此代码纵向视图控制器,在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM