xcode iphone 5 4 英寸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12516986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iphone 5 4 inch
提问by Alessandro
Possible Duplicate:
How to detect iPhone 5 (widescreen devices)?
可能的重复:
如何检测 iPhone 5(宽屏设备)?
I am creating an app using Xcode. I have noticed that with xcode 4.5, your storyboards can adapt to iphone 5 screen size. If I create two separate storyboards with the different screen sizes, but link the controllers to the same .h file, how can I tell the program which storyboard to load depending on the device?
我正在使用 Xcode 创建一个应用程序。我注意到使用 xcode 4.5,您的故事板可以适应 iphone 5 的屏幕尺寸。如果我创建两个不同屏幕尺寸的单独故事板,但将控制器链接到同一个 .h 文件,我如何告诉程序根据设备加载哪个故事板?
eg: for the ipad, when I run, it picks the right storyboard automatically
例如:对于 ipad,当我运行时,它会自动选择正确的故事板
回答by Brennan
The currently marked answer did not work for me so I created the method below to check if the current device has an 4 inch display.
当前标记的答案对我不起作用,因此我创建了以下方法来检查当前设备是否具有 4 英寸显示屏。
- (BOOL)hasFourInchDisplay {
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0);
}
Since that is the known height for the 4 inch display on the iPhone it is a good indicator.
由于这是 iPhone 上 4 英寸显示屏的已知高度,因此它是一个很好的指标。
回答by Comradsky
Add this code in your initializtion:
在您的初始化中添加此代码:
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 (header file) holds the initialization. After the put brackets {} and inside the brackets initialize your data structures such as IBOutlet, int, string. Outside place your methods such as an IBAction
or void
.
.h(头文件)保存初始化。在放置括号 {} 之后和括号内初始化您的数据结构,例如 IBOutlet、int、string。外部放置您的方法,例如 anIBAction
或void
。