新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
你可以手动检查屏幕大小来确定你在哪个设备上:
#define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)
float height = DEVICE_IS_IPHONE5?568:480;
if (height == 568) {
// 4"
} else {
// 3"
}
其他回答
Download and install latest version of Xcode. Set a Launch Screen File for your app (in the general tab of your target settings). This is how you get to use the full size of any screen, including iPad split view sizes in iOS 9. Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly, or used Auto Layout. If you didn't, adjust your view layouts, preferably with Auto Layout. If there is something you have to do for the larger screens specifically, then it looks like you have to check height of [[UIScreen mainScreen] bounds] as there seems to be no specific API for that. As of iOS 8 there are also size classes that abstract screen sizes into regular or compact vertically and horizontally and are recommended way to adapt your UI.
你可以添加以下代码:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960) {
NSLog(@"iPhone 4 Resolution");
}
if(result.height == 1136) {
NSLog(@"iPhone 5 Resolution");
}
}
else{
NSLog(@"Standard Resolution");
}
}
唯一真正需要做的事情是在应用程序资源中添加一个名为“Default-568h@2x.png”的启动图像,在一般情况下(如果你足够幸运)应用程序将正常工作。
如果应用程序不处理触摸事件,那么确保键窗口有适当的大小。解决方法是设置适当的框架:
[window setFrame:[[UIScreen mainScreen] bounds]]
在迁移到iOS 6时,还有其他与屏幕大小无关的问题。详情请阅读iOS 6.0发布说明。
你可以手动检查屏幕大小来确定你在哪个设备上:
#define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)
float height = DEVICE_IS_IPHONE5?568:480;
if (height == 568) {
// 4"
} else {
// 3"
}
在这里你可以找到一个很好的教程(MonoTouch,但你也可以使用非MonoTouch项目的信息): http://redth.info/get-your-monotouch-apps-ready-for-iphone-5-ios-6-today/
为你的splash/default屏幕创建一个新图像(640 x 1136像素),名称为Default-568h@2x.png 在iOS模拟器中,转到硬件->设备菜单,并选择“iPhone(视网膜4英寸)” 创建其他图像,例如背景图像 检测iPhone 5加载你的新图像:
public static bool IsTall
{
get {
return UIDevice.currentDevice.userInterfaceIdiom
== UIUserInterfaceIdiomPhone
&& UIScreen.mainScreen.bounds.size.height
* UIScreen.mainScreen.scale >= 1136;
}
}
private static string tallMagic = "-568h@2x";
public static UIImage FromBundle16x9(string path)
{
//adopt the -568h@2x naming convention
if(IsTall())
{
var imagePath = Path.GetDirectoryName(path.ToString());
var imageFile = Path.GetFileNameWithoutExtension(path.ToString());
var imageExt = Path.GetExtension(path.ToString());
imageFile = imageFile + tallMagic + imageExt;
return UIImage.FromFile(Path.Combine(imagePath,imageFile));
}
else
{
return UIImage.FromBundle(path.ToString());
}
}