Quartz2d--自定义画线

2017-11-17  本文已影响5人  i诺离
- (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];
        }
   
    }
    
}
上一篇 下一篇

猜你喜欢

热点阅读