我假设命名约定如下:
视网膜显示屏,> iPhone 4s
image_name@2x~iphone.png
视网膜显示屏 iPhone 6 plus:
image_name@3x~iphone.png
注意:iPhone 6 plus 的屏幕不是原始尺寸的 3 倍。它是 2.34,所以当你创建 1 到 1 个 44x44 实际像素的像素资产时,我的意思是视网膜上是 88x88,然后是 iPhone 6 plus 上是 103x103。但是您应该为不同的 UI/UX 使用额外的屏幕尺寸,而不是仅仅扩大元素的尺寸。
保持现有大小不缩放的方法是在这些图像资源上固定自动布局,确保这些图像受 x1 大小的约束。就像您的图像是 x1 32 像素平方一样:
UIImageView *imageView= [[UIImageView alloc] initWithFrame:CGRectZero];
imageView.translatesAutoresizingMaskIntoConstraints = NO;
imageView.image=[UIImage imageNamed:@"your_image"];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[image(32)]" options:0 metrics:0 views:@{@"image":@(imageView)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[image(32)]" options:0 metrics:0 views:@{@"image":@(imageView)]];
并使用您的@2x @3x 图像,问题是如果苹果没有为资源提供@3x 命名图像,它将升级下一个最好的@2x 图像。所以可能没有办法轻松避免这种情况。我有点希望苹果能移除基本的 x1 尺寸,因为手机有不同的分辨率。我更喜欢一对一的像素测量约定。
按照 Apple 的要求工作,使用自动布局作为惯例。上面应该保持图像相同,我稍后会得到一个 iPhone plus,所以会测试它。