How to develop or migrate apps for iPhone 5 screen resolution?

后端 未结 30 3229
醉话见心
醉话见心 2020-11-21 05:48

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

相关标签:
30条回答
  • 2020-11-21 05:58

    If you have an app built for iPhone 4S or earlier, it'll run letterboxed on iPhone 5.

    To adapt your app to the new taller screen, the first thing you do is to change the launch image to: Default-568h@2x.png. Its size should be 1136x640 (HxW). Yep, having the default image in the new screen size is the key to let your app take the whole of new iPhone 5's screen.

    (Note that the naming convention works only for the default image. Naming another image "Image-568h@2x.png" will not cause it to be loaded in place of "Image@2x.png". If you need to load different images for different screen sizes, you'll have to do it programmatically.)

    If you're very very lucky, that might be it... but in all likelihood, you'll have to take a few more steps.

    • Make sure, your Xibs/Views use auto-layout to resize themselves.
    • Use springs and struts to resize views.
    • If this is not good enough for your app, design your xib/storyboard for one specific screen size and reposition programmatically for the other.

    In the extreme case (when none of the above suffices), design the two Xibs and load the appropriate one in the view controller.

    To detect screen size:

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480)
        {
            // iPhone Classic
        }
        if(result.height == 568)
        {
            // iPhone 5
        }
    }
    
    0 讨论(0)
  • 2020-11-21 05:59

    First of all create two xibs and attach all delegates,main class to the xib and then u can put in this condition mentioned below in your appdelegate.m file in

    - (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];
    
            }
    

    you can use it any where in the program depending upon your requirements even in your ViewController classes. What matters the most is that you have created two xib files separate for iphone 4(320*480) and iphone 5(320*568)

    0 讨论(0)
  • 2020-11-21 06:00

    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.

    0 讨论(0)
  • 2020-11-21 06:02

    You can use this define to calculate if you are using the iPhone 5 based on screen size:

    #define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
    

    then use a simple if statement :

        if (IS_IPHONE_5) {
    
        // What ever changes
        }
    
    0 讨论(0)
  • 2020-11-21 06:02

    This is a real universal code, you can create 3 different story board:

    Set your project Universal mode, and set your main story iPhone with the iPhone5 storyboard and the ipad main with iPad target storyboard, now add new storyboard target for iphone and modify the resolution for iphone 4s or less now implement your AppDelegate.m

    iPhone4/4s (is the same for 3/3Gs) one for iPhone5 and make the project universal, with a new Storyboard target for iPad, now in to AppDelegate.m under the didFinishLaunching add this code:

        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
            UIStoryboard *storyBoard;
    
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width *scale, result.height *scale);
    
    //----------------HERE WE SETUP FOR IPHONE4/4s/iPod----------------------
    
            if(result.height == 960){
                storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
                UIViewController *initViewController = [storyBoard instantiateInitialViewController];
                [self.window setRootViewController:initViewController];
            }
    
    //----------------HERE WE SETUP FOR IPHONE3/3s/iPod----------------------
    
            if(result.height == 480){
                storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
                UIViewController *initViewController = [storyBoard instantiateInitialViewController];
                [self.window setRootViewController:initViewController];
            }
        }
    
            return YES;
     }
    

    So you have created a Universal app for iPhone 3/3Gs/4/4s/5 All gen of iPod, and All type of iPad

    Remember to integrate all IMG with myImage.png and myImage@2x.png

    0 讨论(0)
  • 2020-11-21 06:02

    According to me the best way of dealing with such problems and avoiding couple of condition required for checking the the height of device, is using the relative frame for views or any UI element which you are adding to you view for example: if you are adding some UI element which you want should at the bottom of view or just above tab bar then you should take the y origin with respect to your view's height or with respect to tab bar (if present) and we have auto resizing property as well. I hope this will work for you

    0 讨论(0)
提交回复
热议问题