Xcode资产目录支持3.5英寸,4英寸和4.7英寸资产. @ 2x图片? [英] Xcode asset catalog support for 3.5", 4", and 4.7" @2x images?

查看:107
本文介绍了Xcode资产目录支持3.5英寸,4英寸和4.7英寸资产. @ 2x图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode为1x,2x,4"2x和3x资产提供资产存储桶.由于2x存储桶用于3.5"和4.7屏幕,因此我的全屏资产在此配置下都是不正确的.目前,我拥有UIImage类别会检查当前的屏幕尺寸,如果设备看起来是3.5,则选择"* -3.5"资产.

Xcode offers asset buckets for 1x, 2x, 4" 2x, and 3x assets. My fullscreen assets are all wonky with this configuration, because the 2x bucket is used for 3.5" and 4.7" screens. Currently I have a UIImage category that introspects the current screen size, and selects a "*-3.5" asset if the device seems to be 3.5".

这很笨重而且不酷.看到Xcode可以为其LaunchImage资产满足所有不同的设备尺寸,我希望有某种方法可以为非启动图像资产提供特定于设备的资产,而无需诉诸代码.

This is clunky and not cool. Seeing that Xcode caters to all the different device sizes for their LaunchImage asset, I was hoping there was some way to supply device specific assets for non launch image assets without resorting to code.

推荐答案

自2014年11月中以来,我已经向Apple报告了一个有关此问题的错误,我只是注意到他们将其标记为无价值",这给了我苹果的印象省略了专门用于iPhone 6的额外插槽.我的猜测是,他们现在希望2x插槽可用于iPhone 6,也许随着年龄的增长,他们正在减少对iPhone 4s的支持.

I have reported a bug to Apple about this since mid November 2014 and I just noticed they marked it as No Value... which gives me the impression Apple has omitted an additional slot for iPhone 6 on purpose. My guess is they now want the 2x slot to be used for iPhone 6, and maybe they're reducing support to iPhone 4s as it's getting old.

如果您真的想继续支持iPhone 4s,建议您在2x插槽中使用iPhone 6尺寸的图像,然后使用以下方法加载图像:

If you really want to keep supporting the iPhone 4s, I'd suggest to use iPhone 6 sized images in the 2x slot, and then use the following method to load your images:

+(UIImage *)loadImageNamed:(NSString *)imageName
{
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    CGFloat screenHeight = MAX(screenSize.width, screenSize.height);
    CGFloat const IPHONE_4_SCREEN_HEIGHT = 480;
    UIImage *image = [UIImage imageNamed:imageName];
    if(screenHeight == IPHONE_4_SCREEN_HEIGHT) {
        CGFloat const xScale = .85333333;//x conversion ratio from iPhone 6's 375 pts width screen to iPhone 4's 320 pts width screen
        CGFloat const yScale = .71964018;//y conversion ratio from iPhone 6's 667 pts height screen to iPhone 4's 480 pts height screen
        CGSize newSize = CGSizeMake(xScale * image.size.width, yScale * image.size.height);
        UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);

        [image drawInRect:(CGRect){0, 0, newSize}];
        UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return resizedImage;
    }
    return image;
}

即使宽高比不同,将大图像(iPhone 6)缩放为较小的图像(iPhone 4)也不会损失太多质量.

Resizing a big image (iPhone 6) to a smaller one (iPhone 4) doesn't lose much quality even if the aspect ration is not the same.

这篇关于Xcode资产目录支持3.5英寸,4英寸和4.7英寸资产. @ 2x图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆