How to develop or migrate apps for iPhone 5 screen

2018-12-31 00:33发布

The new iPhone 5 display has a new aspect ratio and a new resolution (640 x 1136 pixels).

What is required to develop new or transition already existing applications to the new screen size?

What should we keep in mind to make applications "universal" for both the older displays and the new widescreen aspect ratio?

30条回答
后来的你喜欢了谁
2楼-- · 2018-12-31 00:54

Sometimes (for pre-storyboard apps), if the layout is going to be sufficiently different, it's worth specifying a different xib according to device (see this question - you'll need to modify the code to deal with iPhone 5) in the viewController init, as no amount of twiddling with autoresizing masks will work if you need different graphics.

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    NSString *myNibName;
    if ([MyDeviceInfoUtility isiPhone5]) myNibName = @"MyNibIP5";
    else myNibName = @"MyNib";

    if ((self = [super initWithNibName:myNibName bundle:nibBundleOrNil])) {


...

This is useful for apps which are targeting older iOS versions.

查看更多
临风纵饮
3楼-- · 2018-12-31 00:54

I solve this problem here. Just add ~568h@2x suffix to images and ~568h to xib's. No needs more runtime checks or code changes.

查看更多
听够珍惜
4楼-- · 2018-12-31 00:54

I never faced such an issue with any device as I've had one codebase for all, without any hardcoded values. What I do is to have the maximum sized image as resource instead of one for each device. For example, I would have one for retina display and show it as aspect fit so it will be views as is on every device. Coming to deciding the frame of button, for instance, at run time. For this I use the % value of the patent view, example , if I want the width to be half of parent view take 50 % of parent and same applies for height and center.

With this I don't even need the xibs.

查看更多
何处买醉
5楼-- · 2018-12-31 00:55

Checking bounds with 568 will fail in landscape mode. iPhone 5 launches only in portrait mode but if you want to support rotations then the iPhone 5 "check" will need to handle this scenario as well.

Here's a macro which handles orientation state:

#define IS_IPHONE_5 (CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size, CGSizeMake(640, 1136)))

The use of the 'preferredMode' call is from another posting I read a few hours ago so I did not come up with this idea.

查看更多
裙下三千臣
6楼-- · 2018-12-31 00:55

Use the Auto Layout feature for views. It will adjust automatically to all resolutions.

Create two xibs for a controller having controller name with suffix either ~iphone or ~ipad. At compile time, Xcode will take the right xib based on the device.

Use size classes, if you want to create a single xib for both iPhone and iPad, if the view is simple enough to port to iPhone and iPad.

查看更多
残风、尘缘若梦
7楼-- · 2018-12-31 00:56

It's easy for migrating iPhone5 and iPhone4 through XIBs.........

UIViewController *viewController3;
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
    UIViewController *viewController3 = [[[mainscreenview alloc] initWithNibName:@"iphone5screen" bundle:nil] autorelease];               
}    
else
{
     UIViewController *viewController3 = [[[mainscreenview alloc] initWithNibName:@"iphone4screen" bundle:nil] autorelease];
}
查看更多
登录 后发表回答