2014-04-01 40 views
0

我有以下ViewControllers:纵向在一个视图中控制器和在另一个横向

InformationViewController和cardViewController。

我如何确保informationViewController处于纵向模式并且不能旋转。

然后cardViewController应该处于横向模式,不能旋转。

我如何在每个viewController中实现这一点。我在那一刻被激活写真,风景权和一般

+1

虽然下面的一些答案可以帮助您回答这个问题,但我只是提供友好的提醒,表明这种情况违反了用户界面的建议。它提供了糟糕的用户体验来强制用户在视图之间旋转设备,除非有非常明确和明确的需求。虽然您可以有效地使用它,但重新考虑用例并确定您是否真的需要这样做。 – mrosales

回答

0

在信息视图控制器

- (BOOL)shouldAutorotate 

{ 

    return YES; 
} 


- (NSUInteger)supportedInterfaceOrientations 

{ 

    return UIInterfaceOrientationMaskPortrait; 
} 

,并在卡片视图控制器

- (BOOL)shouldAutorotate 

{ 

    return YES; 
} 


- (NSUInteger)supportedInterfaceOrientations 

{ 

    return UIInterfaceOrientationMaskLandscape; 
} 

注:请务必在项目一般设定打勾设备取向的纵向和横向模式(部署信息)

0

留在informationViewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

在cardViewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscape); 
} 
+0

是的,这会阻止视图控制器旋转到“禁止”方向。但是当它们中的一个被推倒在另一个或后来的后面时,它不会使设备旋转视图。 –

0

看一看我回答这个问题: Force controllers to Change their orientation in Either Portrait or Landscape

(但不要使用不赞成使用的方法,有更新的方法可以使用它们)

将视图控制器限制在某些方向很容易。但看到如何强制设备实际旋转的另一个答案。 没有这种把戏:如果只有纵向视图控制器在设备处于横向时变得可见,那么无论您如何限制其支持的方向,它都将以横向显示。

相关问题