具有锁定方向的ViewController

时间:2015-10-26 13:55:15

标签: ios objective-c uiviewcontroller orientation-changes

我遇到以下情况的问题:

ViewController A应锁定在横向(左或右)上。 VC A的设置如下:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorotate {
    return NO;
}

ViewController B应该锁定在肖像上。其设置如下:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate {
    return NO;
}

没有导航控制器或标签栏。它只是一个常规视图控制器,然后按下按钮我从ViewController A转到ViewController B

[self performSegueWithIdentifier:@"ViewControllerB" sender:self];

到目前为止,一切都很好。但是,当我解除ViewController B时,ViewController A会出现在肖像上。这就是我解雇VC B的方式:

[self dismissViewControllerAnimated:YES completion:nil];

另一个问题是:当我在ViewController B上并且画像上没问题时,我开始快速地将我的设备从纵向旋转几次到横向,并且尽管有上面的方向规则,它仍会在某个点旋转到横向。有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

fib n = head (fibs n) 尝试使用此方法旋转到所需的方向,以防控制器负载时方向错误:

viewDidAppear:

同样重新定义NSNumber *value = @(UIInterfaceOrientationLandscapeRight); // Or whatever else orientation you need. [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 这样的方法:

shouldAutorotate

并实现此方法:

- (BOOL)shouldAutorotate {
    // Change the YES or NO order depending on your viewController.
    return [UIDevice currentDevice].orientation == UIDeviceOrientationPortrait ? YES : NO;
}