簡(jiǎn)易畫板畫圖
{
//畫布用于顯示的圖層
CAShapeLayer *_layer;
//用于記錄移動(dòng)點(diǎn)路徑
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]實(shí)線
_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;
}