iOS 创建蒙版层
2019-11-10 本文已影响0人
woo_5857
// 创建蒙版层和框架,以确定什么将在视图中可见。
CAShapeLayer*maskLayer = [[CAShapeLayeralloc]init];
CGRect maskRect = CGRectMake(self.startTouchView.frame.origin.x, 0, (CGRectGetMaxX(self.endTouchView.frame) - self.startTouchView.frame.origin.x), self.frame.size.height);
// 创建一个路径并在其中添加矩形。
CGMutablePathRefpath =CGPathCreateMutable();
CGPathAddRect(path,nil, maskRect);
// 设置蒙版层的路径。
[maskLayersetPath:path];
// 释放路径,因为它没有被ARC覆盖。
CGPathRelease(path);
// 设置视图的蒙版。
self.layer.mask= maskLayer;