Iphone开发视图控制器纵向景观没有自动旋转

问题描述:

我有一个viewcontroller推动另一个应该是在横向模式的VC,但它不会自动旋转到横向推时即。仍然是肖像。Iphone开发视图控制器纵向景观没有自动旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
     return YES; 
    } 

    return NO; 
} 

当一个弹出vc并回到第一个控制器都是完美的,它只能以肖像模式显示。

我可以通过旋转手机/模拟器来获得第二个vc旋转,然后坚持自动旋转风景。然后在弹出时也是完美的,返回肖像模式。

那么有没有什么办法可能progamaticly旋转界面到风景。已尝试使用

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; 

但没有很大的成功。状态栏在弹出时停留在横向。

使用此在您的viewDidLoad方法,它应该工作

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight; 
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2); 
[self.view setTransform:rotate]; 

CGRect contentRect = CGRectMake(0, 0, 480, 320); 
self.view.frame = contentRect; 
[self.view setCenter:CGPointMake(160.0f, 240.0f)]; 
+0

有了这个方法,我不得不手动设置为每个视图状态栏?因为如上所述,此解决方案在弹出vc时不会使状态栏自动旋转回肖像。 – Max

+0

不,当您弹出视图时,需要手动将状态栏旋转回人像 – Saphrosit

+0

当视图出现景观美化时,我会在左侧获得一个像1-3px的小空间。在IB中放置全屏图像视图。无论如何摆脱这一点? – Max