新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
我建议在你的应用程序中根据你的UI界面使用自动调整蒙版,这节省了很多麻烦,比为iPhone 4和5屏幕制作不同的UI更好。
其他回答
在这里你可以找到一个很好的教程(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());
}
}
你可以添加以下代码:
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");
}
}
首先,创建两个xib并将所有委托,main类附加到xib,然后你可以在你的appdelegate中放入下面提到的条件。M文件在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
self.ViewController = [[ViewController alloc] initWithNibName:@"ViewControlleriphone5" bundle:nil];
}
else
{
self.ViewController = [[ViewController alloc] initWithNibName:@"ViewControlleriphone4" bundle:nil];
}
你可以在程序的任何地方使用它,这取决于你的需求,甚至在你的ViewController类中。最重要的是,您已经为iphone 4(320*480)和iphone 5(320*568)分别创建了两个xib文件。
首先显示这张图片。在那个图像中,你显示了视网膜4支持的警告,所以点击这个警告,然后点击添加,这样你的视网膜4启动屏幕自动添加到你的项目中。
在你使用这段代码之后
if([[UIScreen mainScreen] bounds].size.height == 568)
{
// For iphone 5
}
else
{
// For iphone 4 or less
}
使用视图的自动布局功能。它将自动调整到所有分辨率。
为控制器名称后缀为~iphone或~ipad的控制器创建两个xib。在编译时,Xcode将根据设备取正确的xib。
使用大小类,如果你想为iPhone和iPad创建一个单独的xib,如果视图足够简单,可以移植到iPhone和iPad。