iphone 5 4英寸

Ale*_*dro 6 xcode ios

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

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

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

Bre*_*nan 49

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

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

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

  • 我已经停止检查确切的屏幕高度,并且我已经学会了从NIB弯曲UI并且它工作得非常好.我还必须调整图像大小并创建此解决方案.http://stackoverflow.com/questions/12648129/uiimageview-programmilly-manage-for-iphone5-and-iphone4/12774544#12774544 (2认同)

Com*_*sky 6

在初始化中添加此代码:

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 *)];
  }
}
Run Code Online (Sandbox Code Playgroud)

.h(头文件)保存初始化.在括号{}之后和括号内部初始化您的数据结构,如IBOutlet,int,string.外面你的方法,如IBActionvoid.