新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
在iOS设备和iOS模拟器上测试时,有一个小问题。看起来模拟器(XCode 6.0.1)在[[UIScreen mainScreen] bounds]中给出了宽度和高度的切换值。大小,取决于设备方向。
因此,在确定正确的物理屏幕尺寸时,这可能是一个问题。此代码还有助于区分所有2014年。iPhone型号:
iPhone4s iPhone5(和iPhone5s) iPhone6(及iPhone6+)
它也可以很容易地改变,使区别,如iPhone6从iPhone6+。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
if (iOSDeviceScreenSize.width > 568 || // for iOS devices
iOSDeviceScreenSize.height > 568) // for iOS simulator
{ // iPhone 6 and iPhone 6+
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone6
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone6" bundle:nil];
NSLog(@"loaded iPhone6 Storyboard");
}
else if (iOSDeviceScreenSize.width == 568 || // for iOS devices
iOSDeviceScreenSize.height == 568) // for iOS simulator
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone5
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
NSLog(@"loaded iPhone5 Storyboard");
}
else
{ // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
storyboard = [UIStoryboard story boardWithName:@"MainStoryboard_iPhone" bundle:nil];
NSLog(@"loaded iPhone4 Storyboard");
}
}
else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{ // The iOS device = iPad
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPadnew" bundle:nil];
NSLog(@"loaded iPad Storyboard");
}
// rest my code
}
其他回答
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.
使用xCode 5,在项目>General上选择“迁移到资产目录”。
然后使用“Show in finder”找到你的启动图像,你可以模拟编辑它为640x1136,然后拖到资产目录,如下图所示。
确保iOS7和iOS6 R4部分都有一个640x1136的图像。下次你启动应用程序时,黑条将消失,你的应用程序将使用4英寸的屏幕
唯一真正需要做的事情是在应用程序资源中添加一个名为“Default-568h@2x.png”的启动图像,在一般情况下(如果你足够幸运)应用程序将正常工作。
如果应用程序不处理触摸事件,那么确保键窗口有适当的大小。解决方法是设置适当的框架:
[window setFrame:[[UIScreen mainScreen] bounds]]
在迁移到iOS 6时,还有其他与屏幕大小无关的问题。详情请阅读iOS 6.0发布说明。
我想,它不是在所有情况下都能工作,但在我的特定项目中,它避免了我对nib文件的重复:
在common.h中,你可以根据屏幕高度来做这些定义:
#define HEIGHT_IPHONE_5 568
#define IS_IPHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 ([[UIScreen mainScreen] bounds ].size.height == HEIGHT_IPHONE_5)
在你的基本控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
if (IS_IPHONE_5) {
CGRect r = self.view.frame;
r.size.height = HEIGHT_IPHONE_5 - 20;
self.view.frame = r;
}
// now the view is stretched properly and not pushed to the bottom
// it is pushed to the top instead...
// other code goes here...
}
使用视图的自动布局功能。它将自动调整到所有分辨率。
为控制器名称后缀为~iphone或~ipad的控制器创建两个xib。在编译时,Xcode将根据设备取正确的xib。
使用大小类,如果你想为iPhone和iPad创建一个单独的xib,如果视图足够简单,可以移植到iPhone和iPad。