繁体   English   中英

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

[英]Issues with migrating my app to iphone5 resolution

我正在尝试为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"]];
    }

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

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

需要一些指导来解决它。 谢谢..可以指出我在做的错误...

为什么要再次为iPhone 5分辨率分配backgroundimageView 只需使用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-568h@2x.png”(不是image1-568h@2x.png),请重命名默认图像名称,然后再次检查,您将获得正确的屏幕尺寸。

您也可以通过宏检查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