@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语言写一个程序跟她表白。这...