在导航时,我们有没有办法强制将应用程序方向从纵向改为横向?
我的要求是,在从A推送控制器到B时,B应该是横向的,但我的A控制器是纵向的。
在导航时,我们有没有办法强制将应用程序方向从纵向改为横向?
我的要求是,在从A推送控制器到B时,B应该是横向的,但我的A控制器是纵向的。
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
float angle = M_PI/2; //rotate 180°, or 1 π radians
self.view.layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0);
- (void)viewWillAppear:(BOOL)animated
方法中,可以这样说: //this is to force the application to re-evaluate device orientation
//comment the last lines and see
//cannot use [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
//as "setOrientation" is a private method, and we risk to be kicked out by Apple
UIViewController *c = [[[UIViewController alloc]init] autorelease];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
...但首先,在您的xib中,将视图的方向设置为所需的方向
根据我在上一个应用程序中尝试相同操作的经验,我在Stack Overflow上找到了答案,告诉我不要在基于导航的应用程序中强制更改方向。
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return NO;
else
return YES;
}
这个函数可以让您在所需的方向中使用视图控制器,在这种情况下,我已将其设置为横向,并禁止在纵向模式下旋转。
您会面临B视图控制器先加载A视图控制器上的方向的问题。所以我改变了整个应用程序的方向为横向。 希望这有所帮助。
-shouldAutorotateToInterfaceOrientation:
方法。这只是一个想法。 - holexUIInterfaceOrientationPortrait
中,你想为单个视图更改界面方向吗? - h4cky