我正在创建一个应用程序,在这个应用程序中,当我在屏幕上滑动手指时,我会使用代码绘制线条。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),3.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.5, 0.6, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endPoint.x, endPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
}
同时,我也在使用代码移动该行上的箭头。
-(void)moveBallConstantly
{
[UIView animateWithDuration:0.01f animations: ^{
[appDel.ballImageView setCenter:CGPointMake(appDel.ballImageView.center.x + (x/increamentFraction), appDel.ballImageView.center.y + (y/increamentFraction))];
}];
}
这只是一个小部分的功能。我可以不断地移动箭头,但为了使箭头移动更加平滑,我会使用定时器反复调用此函数。
由于我同时进行两种处理,所以有时会出现问题。有时箭头移动方法会延迟,有时线条绘制方法会延迟。