仅在一个UIViewController上强制横向视图

时间:2016-07-20 17:32:29

标签: ios objective-c uiviewcontroller

我的应用只是肖像模式。我只有一个View Controller需要强制进入横向模式(客户签名视图),因此客户有更多的空间来签名。

如何强制一个ViewController以横向模式显示。将其余部分留作肖像?

我尝试将应用的常规部署信息设置为纵向,横向左侧

enter image description here

然后在签名视图

上使用此代码
- (BOOL)shouldAutorotate {
    return YES;
}

并在所有其他视图控制器上返回 NO 。但这似乎不起作用。

我也包括

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
}

这可能吗?

3 个答案:

答案 0 :(得分:0)

如果你的UIViewController是导航控制器的rootcontroller,你需要将代码放在navigationcontroller中,你只需要下面的代码。希望这有帮助,祝你好运。

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

答案 1 :(得分:0)

在签名视图控制器中尝试此代码

 - (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}

答案 2 :(得分:0)

以下是它为我工作的方式: -

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

and 

- (BOOL)shouldAutorotate {
    return NO;
}

另一种方法是在prepareForSegue中定义方向并定义所需VC的方向,并在该VC中将shouldAutorotate设置为NO。

如果提到的代码不适合您,请告诉我。