答案 0 :(得分:6)
代码
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
UIBezierPath * bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:CGPointMake(0, 0)];
[bezierPath addLineToPoint:CGPointMake(0,100)];
[bezierPath addLineToPoint:CGPointMake(10,100)];
[bezierPath addLineToPoint:CGPointMake(20,90)];
[bezierPath addLineToPoint:CGPointMake(30, 100)];
[bezierPath addLineToPoint:CGPointMake(200,100)];
[bezierPath addLineToPoint:CGPointMake(200, 0)];
[bezierPath closePath];
shapeLayer.path = bezierPath.CGPath;
self.imageview.layer.mask = shapeLayer;
注意:剪辑部分仍然可以作为Imageview
的一部分捕获触摸事件或手势,您可以将pointInside
重写为忽略触摸事件
编辑关于其工作原理
你只需要创建你喜欢的任何形状,我只是创建一个像这样的形状的代码,然后用这个形状来设置面具
所以,如果你想制作一个右箭头,只需创建一个这样的形状
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
UIBezierPath * bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:CGPointMake(0, 0)];
[bezierPath addLineToPoint:CGPointMake(0,100)];
[bezierPath addLineToPoint:CGPointMake(170,100)];
[bezierPath addLineToPoint:CGPointMake(180,90)];
[bezierPath addLineToPoint:CGPointMake(190, 100)];
[bezierPath addLineToPoint:CGPointMake(200,100)];
[bezierPath addLineToPoint:CGPointMake(200, 0)];
[bezierPath closePath];
shapeLayer.path = bezierPath.CGPath;
形状截图
所以,您需要的是