I use CAShapeLayer.path and CALayer.mask to configure the image mask, I can achieve the “difference” and “merge” CGPath for CGPath by setting
maskLayer.fillRule = kCAFillRuleEvenOdd/kCAFillRuleZero
However, how can I get the intersection of two paths? I can't achieve this with the odd rule
Here is an example: 
let view = UIImageView(frame: CGRectMake(0, 0, 400, 400)) view.image = UIImage(named: "scene.jpg") let maskLayer = CAShapeLayer() let maskPath = CGPathCreateMutable() CGPathAddEllipseInRect(maskPath, nil, CGRectOffset(CGRectInset(view.bounds, 50, 50), 50, 0)) CGPathAddEllipseInRect(maskPath, nil, CGRectOffset(CGRectInset(view.bounds, 50, 50), -50, 0)) maskLayer.path = maskPath maskLayer.fillRule = kCAFillRuleEvenOdd maskLayer.path = maskPath view.layer.mask = maskLayer
How can I get the middle part of this image? I mean only the middle part (which is empty in the sample view).
I can do this easily in vector design software such as AI, so I think there should be a way to handle it.
source share