重新定位/调整UIBezierPath的大小 [英] Reposition/resize UIBezierPath
问题描述
我有一个可拖动的视图,上面有一个遮罩层。掩码层上有一个UIBezierPath,它使视图上的区域透明/透明(我想要的效果)。我的最终目标是通过传递一个基于我的视图和另一个矩形的交集计算的CGRect来改变路径(不是遮罩层!)的位置和大小(基本上我想隐藏相交的区域)。 / p>
1)我如何创建蒙版和路径(在我的视图上创建一个透明矩形):
self.maskLayer = [CAShapeLayer layer];
self.maskLayer.frame = self.contentView.bounds;
//默认路径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;
2)我的问题是我找不到调整大小/重新定位路径的方法。我在网上搜索但找不到任何解决方案。
此代码不起作用但是我能想到:
//在拖动视图时运行(使用UIPanGestureRecognizer)
- (void)move {
CGRect intersectedRect = CGRectIntersection(self.frame,self .productView.frame);
path = [UIBezierPath bezierPathWithRect:intersectedRect];
[path appendPath:[UIBezierPath bezierPathWithRect:intersectedRect]];
[self.maskLayer setNeedsDisplay];
}
如何操作移动函数中遮罩层的路径?
谢谢!
您需要将更新的路径分配给 self.maskLayer。你的移动方法中的路径
。
I have a draggable view that has a mask layer on it. The mask layer has a UIBezierPath on it which makes an area on the view see-through/transparent(the effect that i want). My end goal is to change the position and size of the path(not the mask layer!) by passing a CGRect that is calculated based on the intersection of my view and another rectangle(Basically I want to hide the area that intersects).
1)How I create my mask and path(creates a see-through rectangle on my view):
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;
2) My problem is that I couldn't find a way to resize/reposition just the path. I searched online but couldn't find any solution.
This code is not working but is what I could think of:
//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];
}
How can I manipulate just the path of the masklayer in my move function? Thank you!
You need to assign the updated path to self.maskLayer.path
in your move method.
这篇关于重新定位/调整UIBezierPath的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!