masking UIView based on CGRect

2019-07-19 08:39发布

Look at the image please : enter image description here

I have UIView and CGRect. I have to check where CGRect overlays UIView and then set the mask on the area which is "opposed" to intersection. So it's blue part in the image. How to achieve that? I know there's CGContextClipToMask but I have no idea how to use that - could someone help me with example code? Is CGContextClipToMask good direction?

Thanks!

1条回答
Anthone
2楼-- · 2019-07-19 09:19

You can assign mask layer to your UIView's layer.

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
view.layer.mask = maskLayer;

CGPathRef path = CGPathCreateMutable();
// Construct path and set it.
[maskLayer setPath:path];
CGPathRelease(path);

[maskLayer release];

Documentation: CALayer reference

查看更多
登录 后发表回答