iphone:在导航上强制将方向从纵向更改为横向

iphone:在导航上强制将方向从纵向更改为横向,iphone,objective-c,uinavigationcontroller,orientation,landscape,Iphone,Objective C,Uinavigationcontroller,Orientation,Landscape,我们有没有办法在导航时强制将应用程序方向从纵向更改为横向 我有一个要求,当把控制器从a推到B时,B应该是横向的,但我的a控制器是纵向的。在-(void)视图中将出现:(BOOL)动画的说: //this is to force the application to re-evaluate device orientation //comment the last lines and see //cannot use [[UIDevice currentDevice] se

我们有没有办法在导航时强制将应用程序方向从纵向更改为横向

我有一个要求,当把控制器从a推到B时,B应该是横向的,但我的a控制器是纵向的。

-(void)视图中将出现:(BOOL)动画的
说:

    //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中,将视图的方向设置为所需的方向。

根据我在上一个应用程序中的经验,我在堆栈溢出上找到了答案,告诉我不要在基于导航的应用程序中强制更改方向

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        return NO;
else
    return YES;
}
此函数将允许您在所需的方向上使用视图控制器,在本例中,我已将其设置为横向,并禁止在纵向模式下旋转

您将面临在视图控制器上的方向上首先加载B视图控制器的问题。因此,我将应用程序的全方位改为横向。
希望这有帮助。

在您的ViewController-B中,在viewDidLoad中添加以下代码行:

  [[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);
如果您使用导航控制器从A移动到B,则此代码工作正常

我用过这个

希望这对你有帮助


享受编码:)

尝试使用不同的
-每个类中的shouldAutorotateToInterfaceOrientation:
方法。这只是一个想法。你在
UIInterfaceOrientationPortrait
中有应用程序,你想更改单视图的界面方向吗?啊,当我尝试这个时,它是在iOS 5中,谢谢你提供的信息:)