简体   繁体   English

将我的应用迁移到iphone5分辨率时出现问题

[英]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. 我正在尝试为iPhone 5迁移我的应用程序。我已经在stackoverflow中看到了其他问题,并且在正确显示它时仍然遇到一些问题。

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. 我为backgroundimageView设置的尺寸在尺寸检查器中为320 x370,image1-568h@2x.png的图像尺寸为640x 1136,image1.png的图像尺寸为640x733。因此,对于3.5英寸的屏幕,它应该显示通常情况下,对于4英寸的屏幕,应相应调整尺寸。

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. 但是问题在于,对于4英寸的屏幕,它没有调整大小,最终显示出与3英寸的屏幕相同的效果,但带有白色边框以覆盖其余区域。

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. 为什么要再次为iPhone 5分辨率分配backgroundimageView Just use the same IBOutlet of backgroundimageView and modify the frame and image of it. 只需使用backgroundimageView的相同IBOutlet并修改其框架和图像即可。

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. 默认图像名称必须为“ Default-568h@2x.png”(不是image1-568h@2x.png),请重命名默认图像名称,然后再次检查,您将获得正确的屏幕尺寸。

Also you can check iphone5 by macros. 您也可以通过宏检查iphone5。

#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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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