#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) CAShapeLayer *shapeLayer;
@property (nonatomic, strong) UIBezierPath *path;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.shapeLayer = [CAShapeLayer layer];
self.shapeLayer.frame = self.view.bounds;
self.shapeLayer.strokeColor = [UIColor redColor].CGColor;
self.shapeLayer.fillColor = [UIColor clearColor].CGColor;
self.shapeLayer.lineJoin = kCALineJoinRound;
self.shapeLayer.lineCap = kCALineCapRound;
self.shapeLayer.lineWidth = 5;
[self.view.layer addSublayer:_shapeLayer];
self.path = [[UIBezierPath alloc] init];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
CGPoint point = [[touches anyObject] locationInView:self.view];
[self.path moveToPoint:point];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
CGPoint point = [[touches anyObject] locationInView:self.view];
[self.path addLineToPoint:point];
self.shapeLayer.path = self.path.CGPath;
}
@end
网友评论