Ios 目标c-透明绘制视图(UIVisualEffectView)
我想在视图上创建一个透明的绘图(就像黄色视图中的红色绘图)。 我有一些视图(Ios 目标c-透明绘制视图(UIVisualEffectView),ios,objective-c,Ios,Objective C,我想在视图上创建一个透明的绘图(就像黄色视图中的红色绘图)。 我有一些视图(UIVisualEffectView-黄色视图),我想用手指画画,看起来就像我们“擦除”了它 我创建了UIVisualEffectView的子类,并尝试绘制,但效果不太好 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { CGPoint l
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;
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event
{
用于(UITouch*触摸屏)
{
CGPoint位置=[触摸位置查看:自];
CGFloat drawSize=45;
CGRect rect=CGRectMake(location.x,location.y,drawSize,drawSize);
[自检:rect];
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
{
用于(UITouch*触摸屏)
{
CGPoint位置=[触摸位置查看:自];
CGFloat drawSize=45;
[自检:CGRectMake(位置.x,位置.y,drawSize,drawSize)];
}
}
-(无效)测试:(CGRect)rect
{
if(!self.mask)
{
self.mask=[[UIView alloc]initWithFrame:self.bounds];
self.mask.clipstobunds=是;
self.mask.backgroundColor=[UIColor clearColor];
}
如果(!self.fillLayer)
{
self.fillLayer=[CAShapeLayer层];
self.fillLayer.fillRule=kCAFillRuleEvenOdd;
self.fillLayer.fillColor=[UIColor greenColor].CGColor;
}
如果(!self.outerbezierPath)
{
self.outerbezierPath=[UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:0];
self.outerbezierPath.UsesevenodFillRule=否;
}
self.innerCirclepath=[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height*0.5];
[self.outerbezierPath appendPath:self.innerCirclepath];
[self.fillLayer从Superlayer移除];
self.fillLayer.path=self.outerbezierPath.CGPath;
[self.mask.layer addSublayer:self.fillLayer];
self.maskView=self.mask;
}
结果是什么?什么不起作用?取而代之的是平滑的线条,我在画的路径上画了很多圈。