masking UIView based on CGRect

时间秒杀一切 提交于 2019-12-11 02:49:17

问题


Look at the image please :

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:


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



来源:https://stackoverflow.com/questions/7241966/masking-uiview-based-on-cgrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!