3

有什么方法可以在导航时强制将应用方向从纵向更改为风景?iphone:在导航上强制将方向从纵向更改为风景

我有一个要求,同时推控制器从A到B. B应该是在风景,但我的A控制器是肖像。

+0

尝试在每个类中使用不同的'-sharedAutorotateToInterfaceOrientation:'方法。这只是一个想法。 – holex 2012-07-23 10:41:22

+0

您在'UIInterfaceOrientationPortrait'中有应用程序,并且您想更改单个视图的界面方向? – h4cky 2012-07-23 10:55:26

回答

9

在你的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

我已经使用这个。

希望这会帮助你。

享受编码:)

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]; 

...但首先,在你的厦门国际银行,从我的最后一个应用程序中,我试着做了经验设置视图的方向以期望的一个

0

同样,我发现堆栈溢出的答案,告诉不要强行更改基于导航的应用程序中的方向。

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     return NO; 
else 
    return YES; 
} 

这个功能可以让您使用视图控制器在所需方向,在这种情况下,我已经将它设置为景观,在肖像模式不允许旋转。

您将面临B视图控制器首先在视图控制器上的方向加载的问题。所以我将应用程序的完整方向改为风景。 希望这有助于。

+1

请注意,这不适用于iOS 6. – 2012-12-14 13:07:23

+0

啊,当我尝试这是它在iOS 5,感谢信息:) – darkmystel 2013-01-01 18:39:43

相关问题