gpt4 book ai didi

ios - Xcode Assets 目录支持 3. 5", 4"和 4.7"@2x 图像?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:35 24 4
gpt4 key购买 nike

Xcode 为 1x、2x、4"2x 和 3x Assets 提供 Assets 桶。我的全屏 Assets 在这种配置下都不稳定,因为 2x 桶用于 3.5"和 4.7"屏幕。目前我有一个 UIImage 类别内省(introspection)当前屏幕尺寸,如果设备看起来是 3.5",则选择“*-3.5” Assets 。

这很笨重而且不酷。看到 Xcode 为他们的 LaunchImage Assets 迎合了所有不同的设备尺寸,我希望有一些方法可以为非启动图像 Assets 提供设备特定 Assets ,而无需诉诸代码。

最佳答案

自 2014 年 11 月中旬以来,我已向 Apple 报告了一个关于此的错误,我只是注意到他们将其标记为无值(value)...这给我的印象是 Apple 故意省略了 iPhone 6 的额外插槽。我的猜测是,他们现在希望 2x 插槽用于 iPhone 6,并且随着 iPhone 4s 的老化,他们可能会减少对它的支持。

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

+(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) 不会损失太多质量,即使宽高比不同也是如此。

关于ios - Xcode Assets 目录支持 3. 5", 4"和 4.7"@2x 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26219762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com