问题
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