iOS应用程序的iPad方向 - 自新版本

问题描述:

上次我运行我创建的iOS应用程序时,它一定是用于部署目标5.0和相关SDK(有可能早在4.3)。部署现在是6.1。我的应用程序只运行景观,并在景观中运行良好。但在我更新了我的iPad和iOS SDK并在大约一年后第一次运行此应用程序后,似乎有所改变。iOS应用程序的iPad方向 - 自新版本

这些按钮显示为iPad处于纵向模式。这是错误的,因为它应该是在横向(并且它曾经工作得很好)。

最新更新有哪些变化?

我在Xcode中支持的界面方向只有“风景右侧”被选中,并且在信息部分中,我有“支持的界面方向”,只有一个项目:“风景(右侧主页按钮)”。

在打开的应用程序第一次打开时,我有

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
      interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 

,也是viewDidLoad的第一行是

self.view.frame = CGRectMake(0, 0, 1024, 768); 

所以我的主视图控件为什么代码绘制按钮为如果它处于肖像模式?


UPDATE

我试图与

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationLandscapeRight & UIInterfaceOrientationLandscapeLeft; 
} 

更换shouldAutorotateToInterfaceOrientation方法,但它仍然无法正常工作。

+0

所以,现在部署目标是iOS的6.1? – jamapag 2013-02-15 20:47:01

+0

是的,没错。 – CodeGuy 2013-02-15 20:47:18

+0

'应该在iOS 6中弃用shouldAutorotateToInterfaceOrientation'。 – jamapag 2013-02-15 20:49:05

iOS6中的方向更改。0

你应该如果您正在使用TabBarController/NavigationController实现以下方法

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

// Set the initial preferred orientation 
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

注意
你应该子类的视图控制器覆盖以这样一种方式,它应该叫定向方法你拥有视图控制器方法。这是iOS6的重大变化。

#import "UINavigationController+Orientation.h" 

@implementation UINavigationController (Orientation) 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

@end 

shouldAutorotateToInterfaceOrientation在iOS 6中已过时,应重写的UIViewController

supportedInterfaceOrientations方法有引自DOC:

在iOS 6中,您的应用支持在 应用程序的定义的接口方向Info.plist文件。视图控制器可以覆盖 supportedInterfaceOrientations方法以限制支持的 方向的列表。一般来说,系统只会在窗口视图控制器的根目录控制器或视图控制器上显示填充 整个屏幕;子视图控制器使用其父视图控制器为其提供的窗口部分,并且不再支持 直接参与有关旋转 支持的决策。应用程序的方向遮罩和视图控制器的方向遮罩的交集用于确定视图控制器可以旋转到哪个方向。

您可以覆盖旨在以全屏显示 特定方向的视图控制器的preferredInterfaceOrientationForPresentation( )。

+0

我已将shouldAutorotateToInterfaceOrientation替换为supportedInterfaceOrientations(请参阅上面的更新),但问题仍然存在。有任何想法吗? – CodeGuy 2013-02-15 20:58:32

+0

还需要设置'self.window.rootViewController'在'应用中:didFinishLaunchingWithOptions:',比如'self.window.rootViewController = navigationController;'。 – jamapag 2013-02-18 11:17:51