6

可能重复:
如何检测 iPhone 5(宽屏设备)?

我正在使用 Xcode 创建一个应用程序。我注意到使用 xcode 4.5,您的故事板可以适应 iphone 5 的屏幕尺寸。如果我创建两个具有不同屏幕尺寸的独立故事板,但将控制器链接到同一个 .h 文件,我如何告诉程序根据设备加载哪个故事板?

例如:对于 ipad,当我运行时,它会自动选择正确的故事板

4

2 回答 2

48

当前标记的答案对我不起作用,因此我创建了以下方法来检查当前设备是否具有 4 英寸显示屏。

- (BOOL)hasFourInchDisplay {
    return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0);
}

由于这是 iPhone 上 4 英寸显示屏的已知高度,因此它是一个很好的指标。

于 2012-09-21T05:26:33.220 回答
5

在您的初始化中添加此代码:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
     if([UIScreen mainScreen].bounds.size.height == 568.0)){
             //move to your iphone5 storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
     else{
             //move to your iphone4s storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
}

.h(头文件)保存初始化。在放置括号 {} 之后和括号内初始化您的数据结构,例如 IBOutlet、int、string。将您的方法放在外面,例如IBActionor void

于 2012-09-20T17:55:45.323 回答