我想在视图上创建透明绘图(就像黄色视图中的红色绘图)。
我有一些观点(UIVisualEffectView
- 黄色视图),我想用手指画画,看起来我们会“擦掉”它。
我创建了UIVisualEffectView
的子类并尝试绘制,但它的工作效果不佳..
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches)
{
CGPoint location = [touch locationInView:self];
CGFloat drawSize = 45;
CGRect rect = CGRectMake(location.x, location.y, drawSize, drawSize);
[self test:rect];
}
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches)
{
CGPoint location = [touch locationInView:self];
CGFloat drawSize = 45;
[self test:CGRectMake(location.x, location.y, drawSize, drawSize)];
}
}
-(void)test:(CGRect)rect
{
if (!self.mask)
{
self.mask = [[UIView alloc]initWithFrame:self.bounds];
self.mask.clipsToBounds = YES;
self.mask.backgroundColor = [UIColor clearColor];
}
if (!self.fillLayer)
{
self.fillLayer = [CAShapeLayer layer];
self.fillLayer.fillRule = kCAFillRuleEvenOdd;
self.fillLayer.fillColor = [UIColor greenColor].CGColor;
}
if (!self.outerbezierPath)
{
self.outerbezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:0];
self.outerbezierPath.usesEvenOddFillRule = NO;
}
self.innerCirclepath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height * 0.5];
[self.outerbezierPath appendPath:self.innerCirclepath];
[self.fillLayer removeFromSuperlayer];
self.fillLayer.path = self.outerbezierPath.CGPath;
[self.mask.layer addSublayer:self.fillLayer];
self.maskView = self.mask;
}