Xcode 9资产目录是否保留Vector数据不起作用? [英] Xcode 9 asset catalog Preserves Vector Data not working?

查看:101
本文介绍了Xcode 9资产目录是否保留Vector数据不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为Xcode 9资产目录中新的保留矢量数据"复选标记最终将使我们能够调整矢量PDF图像的大小,但显然没有.这是在预览中以两个缩放比例看到的我的测试图像:

I thought the new Preserves Vector Data checkmark in the Xcode 9 asset catalog would finally give us resizing of vector PDF images, but apparently not. Here's my test image seen at two zooms in Preview:

细腻而锐利,具有很大的缩放比例,因此很显然这是矢量图像.但是,这是我的应用程序中的两个图像视图:

Nice and sharp with lots of zoom, so clearly this is a vector image. But here's what two image views look like in my app:

那么我的矢量数据在哪里?这个非常需要的功能 still 在操作中丢失了吗?它仍然仅适用于自动生成的2x和3x图像吗?如果是这样,保留矢量数据"复选框会为我们提供哪些我们还没有的东西?

So where's my vector data? Is this much-desired feature still missing in action? Does it still work only for the automatically generated 2x and 3x images? And if so, what does the Preserve Vector Data checkbox give us that we didn't have already?

推荐答案

它有效,但前提是您自己进行调整大小:

It works, but only if you perform the resizing yourself:

这是通过代码实现的,就像这样:

That was achieved in code, like this:

    let im = UIImage(named:"Image")!
    let r = UIGraphicsImageRenderer(size:self.iv2.bounds.size)
    let im2 = r.image {
        _ in
        im.draw(in: self.iv2.bounds)
    }
    self.iv2.image = im2
    self.iv2.contentMode = .center

因此,UIImageView在缩放时会栅格化(例如,对于Aspect Fit),但是在代码中进行绘制将保留矢量数据.

So UIImageView will rasterize as it scales (e.g. for Aspect Fit), but drawing in code will preserve the vector data.

EDIT 是Xcode 9 beta 5的新增功能,现在可以正常使用了!在此屏幕快照中,第二个图像视图仅按比例缩放即可填充,仅此而已.我们会大幅调整大小!

EDIT New in Xcode 9 beta 5, this now works as expected! In this screen shot, the second image view just does a scale-to-fill, no more. We resize sharply!

编辑在使用Xcode 11时,我终于找到了一个始终有效的公式.这意味着在启动时,无需额外的代码,在图像视图或其他地方,基于矢量的图像无论大小都会显得清晰.

EDIT In playing around with Xcode 11 I have finally found a formula that always works. This means that on launch, with no extra code, in an image view or elsewhere, a vector-based image appears sharp at any size.

在资产目录中,必须将比例"弹出菜单设置为单个比例",然后将基于矢量的图像放入1x插槽.检查保留向量数据.完成.

In the asset catalog, you must set the Scales pop-up menu to Individual Scales and put the vector-based image into the 1x slot. Check Preserve Vector Data. Done.

这篇关于Xcode 9资产目录是否保留Vector数据不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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