[英]How can I display a UIImage on top of a CAShape Layer?
I'm having trouble drawing a UIImage
in front of a CAShapeLayer
. 我在
CAShapeLayer
前面绘制UIImage
时遇到麻烦。 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. 而且我在屏幕上有很多这样的显示,因此为了提高性能,我想在较低的水平上进行操作,而不是使用一堆
UIImageView
子视图。
I've tried: 我试过了:
CAShapeLayer
CAShapeLayer
CAShapeLayer
as a sublayer of my container view CAShapeLayer
添加为容器视图的子层 content
to the image's CGImage
content
设置为图像的CGImage
drawRect
(my Quartz-fu is pretty weak, though) drawRect
手动绘制图像(尽管我的Quartz-fu很弱) 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. 在大多数情况下,我会在形状后面绘制图像(我隐约地理解这是由于
CAShapeLayers
如何合成自身)或根本没有图像。 Surely this is possible without resorting to subviews? 当然可以在不诉诸子视图的情况下做到这一点?
Have you tried setting the zPosition of a sublayer to a positive value? 您是否尝试将子层的zPosition设置为正值? The default is 0.0, so making it larger than zero would push it "higher" in the hierarchy.
默认值为0.0,因此使其大于零会在层次结构中将其“推高”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.