objective-c - iOS UIBezierPath画线如何删除已有的线

查看:556
本文介绍了objective-c - iOS UIBezierPath画线如何删除已有的线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

生成线的代码:
self.path = [UIBezierPath bezierPath];

[self.path moveToPoint:from];
[self.path addLineToPoint:to];
self.pathLayer = [CAShapeLayer layer];
self.pathLayer.frame = containerView.bounds;
self.pathLayer.path = self.path.CGPath;
self.pathLayer.strokeColor = color.CGColor;
self.pathLayer.lineWidth = 2.0f;
self.pathLayer.lineJoin = kCALineJoinBevel;

NSMutableArray *ary = [NSMutableArray arrayWithArray:shapeLayers];
[ary addObject:self.pathLayer];
shapeLayers = [NSMutableArray arrayWithArray:ary];
[containerView.layer addSublayer:self.pathLayer];

如何将上述线删除,在画新线

解决方案

self.pathLayer = [CAShapeLayer layer];之前加上

if (self.pathLayer) {
        [self.pathLayer removeFromSuperlayer];
    }

这篇关于objective-c - iOS UIBezierPath画线如何删除已有的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆