- (void)pan:(UIPanGestureRecognizer *)pan{
CGPoint curP = [pan locationInView:self];
if (pan.state == UIGestureRecognizerStateBegan) {
MyBezierPath *path = [[MyBezierPath alloc] init];
self.path = path;
//设置线宽度
[path setLineWidth:self.Width];
// 避免画完一次线再画下一次的时候,刚才的线消失
[self.pathArray addObject:path];
path.color = self.color;
[path moveToPoint:curP];
}else if(pan.state == UIGestureRecognizerStateChanged){
[self.path addLineToPoint:curP];
[self setNeedsDisplay];
}
}
- (void)drawRect:(CGRect)rect {
// Drawing code
//取出所有的路径
for (MyBezierPath *path in self.pathArray) {
if ([path isKindOfClass:[UIImage class]]) {
UIImage *image = (UIImage *)path;
[image drawInRect:rect];
}else{
[path.color set];
[path stroke];
}
}
}
网友评论