我是目标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);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句