更改所选CAShapeLayer的fillColor

Fra*_*ank 8 iphone core-animation objective-c calayer

我试图在触摸包含它的图层时更改CAShapeLayer的fillColor.我可以像这样更改tapped图层的背景颜色:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point];
layer = layer.modelLayer;
layer.backgroundColor = [UIColor blueColor].CGColor;
}
Run Code Online (Sandbox Code Playgroud)

这将"层"的背景变为预期的蓝色.我的问题是如何在"图层"中更改CAShapelayer的颜色?谢谢!

Way*_*man 17

A CAShapeLayer有一个属性,fillColor你可以传入一个CGColor来改变:

CAShapeLayer* shapeLayer = (CAShapeLayer*)layer.modelLayer;
shapeLayer.fillColor = [UIColor blueColor].CGColor;
Run Code Online (Sandbox Code Playgroud)

另请参见:CAShapeLayer类参考