简易画板画图
{
//画布用于显示的图层
CAShapeLayer *_layer;
//用于记录移动点路径
UIBezierPath *_beziePath;
}
- (void)viewDidLoad {
[super viewDidLoad];
//
_layer = [CAShapeLayer layer];
_layer.frame = self.view.frame;
_layer.backgroundColor = [UIColorcyanColor].CGColor;
_layer.strokeColor = [UIColororangeColor].CGColor;
_layer.lineWidth = 5;
//@[@10]虚线
//@[@10,@0]实线
_layer.lineDashPattern = @[@10,@0];
_layer.fillColor = [UIColorclearColor].CGColor;
_layer.lineCap = @"round";
_layer.lineJoin = @"round";
[self.view.layer addSublayer:_layer];
_beziePath = [[UIBezierPath alloc] init];
_layer.path =_beziePath.CGPath;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint point = [[touches anyObject] locationInView:self.view];
[_beziePath moveToPoint:point];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint point = [[touches anyObject] locationInView:self.view];
[_beziePath addLineToPoint:point];
_layer.path =_beziePath.CGPath;
}