画线目标c

埃琳娜·法雅斯

我是目标C的初学者,我试图制作一个具有Paint风格的程序,我正在用平移手势绘制一条线。我可以做出手势,但是问题是,每次重新加载之前删除鼠标的位置时,我都无法在鼠标经过的位置后面拖动。帮助!非常感谢!这是该部分中的代码:

-(void)pan: (UIPanGestureRecognizer*)panGesture
{
    if(panGesture.state == UIGestureRecognizerStateChanged) {    
        _panLocation = [panGesture locationInView:self];
    }
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self drawLine:context];
}

-(void)drawLine:(CGContextRef)context {    
    if (self.tag == 0) {
        [[UIColor blackColor] setFill];
        UIGraphicsPushContext(context);
        CGContextBeginPath(context);
        CGContextAddArc(context, _panLocation.x, _panLocation.y, 4, 0, 2*M_PI, YES);
        CGContextSetAlpha(context, 1);
        CGContextFillPath(context);
    }
}
简门再也

我想这会有所帮助

使用UIPanGestureRecognizer进行绘制时,请参考带有手势链接的绘制线

否则,您可以使用该链接后面的触摸委托方法来执行此操作

触摸画线

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章