我有一个可拖动视图,其上有一个蒙版层。蒙版层上有一个UIBezierPath,它使视图上的某个区域变为透明(这是我想要的效果)。我的最终目标是通过传递一个CGRect来更改路径的位置和大小(而不是蒙版层!),该CGRect是根据我的视图和另一个矩形的交集计算出来的(基本上我想隐藏相交的区域)。
1)如何创建我的蒙版和路径(在我的视图上创建一个透明的矩形):
self.maskLayer = [CAShapeLayer layer];
self.maskLayer.frame = self.contentView.bounds;
//default path rect
CGRect const rect = CGRectMake(CGRectGetMidX(self.contentView.bounds) ,
CGRectGetMidY(self.contentView.bounds),
50,50);
path = [UIBezierPath bezierPathWithRect:rect];
[path appendPath:[UIBezierPath bezierPathWithRect:self.contentView.frame]];
self.maskLayer.path = path.CGPath;
self.maskLayer.fillRule = kCAFillRuleEvenOdd;
self.contentView.layer.mask = self.maskLayer;
我的问题是我找不到一种方法来调整/重新定位路径。我在网上搜索过,但找不到任何解决方案。
以下是我能想到的代码,但它并没有起作用:
//runs while the view is being dragged(using UIPanGestureRecognizer)
-(void)move{
CGRect intersectedRect = CGRectIntersection(self.frame, self.productView.frame);
path = [UIBezierPath bezierPathWithRect:intersectedRect];
[path appendPath:[UIBezierPath bezierPathWithRect:intersectedRect]];
[self.maskLayer setNeedsDisplay];
}
如何在我的移动函数中仅操作masklayer的路径?谢谢!