如何将旋转限制为仅一个视图控制器?

问题描述:

有没有办法将视图旋转限制为只有一个视图控制器? 例如,应用程序的其余部分保持纵向模式,但一个视图可以处于横向或纵向模式。如何将旋转限制为仅一个视图控制器?

使用该委托方法来控制旋转,

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     // Return YES for supported orientations 
     return YES; 
    } 
    else 
    { 
     return NO; 
    } 
} 

你想要支持的方向返回YES和NO他人。你可以在所有的视图控制器中实现它。

您可以执行每个UIViewControllershouldAutorotateToInterfaceOrientation:方法。对于您希望给定的视图控制器支持的方向,请返回YES将产生所需的结果。

请参阅the UIViewController docs