@interface CustomView ()
@property (nonatomic, strong) CAShapeLayer *shaperLayer;
@property (nonatomic, strong) UIBezierPath *bezierPath;
@end
@implementation CustomView
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = touches.anyObject;
CGPoint startPoint = [touch locationInView:self];
self.bezierPath = [UIBezierPath bezierPath];
[self.bezierPath moveToPoint:startPoint]; //起始点
self.shaperLayer = [[CAShapeLayer alloc] init];
self.shaperLayer.fillColor = [[UIColor clearColor] CGColor];
self.shaperLayer.strokeColor = [[UIColor greenColor] CGColor];
self.shaperLayer.lineWidth = 20;
self.shaperLayer.lineCap = kCALineCapRound; //端点圆角
self.shaperLayer.lineJoin = kCALineJoinRound; //连接点圆角
[self.layer addSublayer:self.shaperLayer];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = touches.anyObject;
CGPoint currentPoint = [touch locationInView:self];
[self.bezierPath addLineToPoint:currentPoint]; //连接点
self.shaperLayer.path = self.bezierPath.CGPath;
}
@end
简单画板(用UIBezierPath和CAShapeLayer几行代码)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- iOS 画板--UIBezierPath和CAShapeLayer实现 最近在做的项目中,用到画板的功能,现在项目...
- 喜欢一个女生,又不知道如何表白,怎么办?教你用python做一个表白神器!简单神奇又好用! 1. 准备工作 导入t...
- 喜欢一个女生很久了,想跟那个女生表白,但是找不到合适的方式表白。于是想到了一个办法,用c语言写一个程序跟她表白。这...