畫圖4

簡易畫板畫圖


{

//畫布用于顯示的圖層

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;

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容