我在xcassets中使用了一些pdf图像,并选中了“保留矢量数据”。在不同的iOS版本中,同一张图片的呈现方式有所不同(我使用的是Xcode 11.2)。左侧,图像按iOS 13.2中的预期进行渲染,右侧图像不按iOS 11.4中的预期进行渲染(与iOS 12.2中的相同)。通过取消选中“保留矢量数据”,该问题不会出现。
创建UIImageViews的代码是这样的:
self.view.backgroundColor = .white
let imageView = UIImageView(frame: CGRect(x: 10,y: 20,width: self.view.bounds.width - 20,height: self.view.bounds.width - 20))
imageView.image = UIImage(named: "calendar")
imageView.backgroundColor = UIColor.red.withAlphaComponent(0.4)
imageView.contentMode = .center
self.view.addSubview(imageView)
Pdf图像尺寸为27x23像素,并且通过停止模拟器并打印出图像尺寸和比例仍可打印正确的值:
(lldb) po ((UIImageView *) 0x7fa1b0c053e0).image.scale
2
(lldb) po ((UIImageView *) 0x7fa1b0c053e0).image.size
(width = 27,height = 23)
我想念什么吗?