如何在 CAShape 图层之上显示 UIImage?
我在 CAShapeLayer
前面绘制 UIImage
时遇到问题。我的背景中有一个矢量图像,前面有一个图标。该向量很重要,因为我最终要缩放和动画化;我在屏幕上有很多这样的东西,所以为了性能,我想在比使用一堆 UIImageView
子视图更低的级别上执行此操作。
我尝试过:
- 将容器视图的图层类设置为 CAShapeLayer
- 添加一个 CAShapeLayer 作为容器视图的子图层
- 设置容器的图层和/或子图层的内容/code> 到图像的
CGImage
- 在容器视图的
drawRect
中手动绘制图像(尽管我的 Quartz-fu 相当弱)
在大多数情况下我获取在形状后面绘制的图像(我模糊地理解这是由于 CAShapeLayers 自身的合成方式所致)或根本没有图像。不借助子视图这当然是可能的吗?
I'm having trouble drawing a UIImage
in front of a CAShapeLayer
. I have a vector image in the background with an icon in front of it. The vector is important because I'm eventually scaling & animating this; and I have a ton of these onscreen so for performance I'd like to do this at a lower level than with a bunch of UIImageView
subviews.
I've tried:
- Setting the container view's layer class to
CAShapeLayer
- Adding a
CAShapeLayer
as a sublayer of my container view - Setting my container's layer and/or sublayer's
content
to the image'sCGImage
- Manually drawing the image in the container view's
drawRect
(my Quartz-fu is pretty weak, though)
In most cases I get the image drawn behind the shape (I vaguely understand that this is due to how CAShapeLayers
composite themselves) or no image at all. Surely this is possible without resorting to subviews?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将子图层的 zPosition 设置为正值?默认值为 0.0,因此使其大于零会将其推到层次结构中的“更高”位置。
Have you tried setting the zPosition of a sublayer to a positive value? The default is 0.0, so making it larger than zero would push it "higher" in the hierarchy.