本文介绍了UIImage作为CAShapeLayer的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个仅显示背景颜色的CAShapeLayer,但如果我将内容设置为图像,则不会显示任何内容。

If I create a CAShapeLayer with just a background color it shows up, but if i set the content to an image, nothing shows.

CAShapeLayer* leftDot = [CAShapeLayer layer];
leftDot.opacity = 1.0;
leftDot.frame = CGRectMake(leftRef.CGPointValue.x, leftRef.CGPointValue.y, 2 * radius, 2 * radius);
leftDot.position = CGPointMake(leftRef.CGPointValue.x + 4, leftRef.CGPointValue.y + 4);
leftDot.cornerRadius = radius;
[leftDot setContents:[UIImage imageNamed: @"glow.png"]];

[self.layer addSublayer: leftDot];


推荐答案

CAShapeLayer无法正常工作。您可以创建一个普通的CALayer,将图像作为其内容,然后使用形状图层作为该图层的蒙版,以达到您所追求的效果。

CAShapeLayer doesn't work that way. You would create a normal CALayer with the image as its content and then use the shape layer as the mask of that layer to achieve the effect you are after.

这篇关于UIImage作为CAShapeLayer的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:46