简体   繁体   中英

Issues with migrating my app to iphone5 resolution

I am trying to migrate my app for iphone 5. I have already seen the other questions in stackoverflow and still facing the some problems in correctly showing it.

CGRect screenBounds = [[UIScreen mainScreen] bounds];
    if (screenBounds.size.height == 568) {
        // code for 4-inch screen
        _backgroundimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,500)];
        [_backgroundimageView setImage:[UIImage imageNamed:@"image1-568h@2x.png"]];
    } else {
        // code for 3.5-inch screen
        [_backgroundimageView setImage:[UIImage imageNamed:@"image1.png"]];
    }

The size I have set for backgroundimageView is 320 x370 in the size inspector and the image size of image1-568h@2x.png has a size of 640x 1136 and of image1.png is 640x733.So, for 3.5 inch screen, it should show normally and for 4-inch screen, it should resize accordingly.

But the problem is that for 4-inch screen, it doesn't resize and ends up showing me the same as 3inch screen with some white border to cover the remaining area.

Need some guidance to solve it. Thanks.. Can point out the mistake i am doing...

Why you are again allocating backgroundimageView for iPhone 5 resolutions. Just use the same IBOutlet of backgroundimageView and modify the frame and image of it.

CGRect screenBounds = [[UIScreen mainScreen] bounds];
    if (screenBounds.size.height == 568) {
        // code for 4-inch screen
        _backgroundimageView.frame = CGRectMake(0,0,320,460);
        [_backgroundimageView setImage:[UIImage imageNamed:@"image1-568h@2x.png"]];
    } else {
        // code for 3.5-inch screen
         _backgroundimageView.frame =CGRectMake(0,0,320,370);
        [_backgroundimageView setImage:[UIImage imageNamed:@"image1.png"]];
    }

Default image name must be "Default-568h@2x.png" (not image1-568h@2x.png) try renaming the default image name and check again, you will get right screen size.

Also you can check iphone5 by macros.

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)

我认为您的imageview的内容模式是中心,因此请为您的imageview尝试此模式

[_backgroundimageView setContentMode:UIViewContentModeScaleAspectFill]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM