Iphone 使用CoreGraphics和CGContextAddLine绘制速度变化的动画线
我创建了一个iPhone应用程序,它使用CLLocation(CoreLocation框架)显示您当前的速度 这是我在标签中显示当前速度的代码。我想添加一个小的动画线与你的速度起伏(自动工作) 结果应该是这样的: 我认为这应该是可能的CGContextAddLine(CoreGraphics) 我看到了这个问题,但我仍然不清楚:Iphone 使用CoreGraphics和CGContextAddLine绘制速度变化的动画线,iphone,ios,objective-c,core-graphics,Iphone,Ios,Objective C,Core Graphics,我创建了一个iPhone应用程序,它使用CLLocation(CoreLocation框架)显示您当前的速度 这是我在标签中显示当前速度的代码。我想添加一个小的动画线与你的速度起伏(自动工作) 结果应该是这样的: 我认为这应该是可能的CGContextAddLine(CoreGraphics) 我看到了这个问题,但我仍然不清楚: 谢谢 此代码获取图形上下文并在其中绘制一条黑色线,根据保存的点与最后一个点之间的距离,到不同的位置 UIGraphicsBeginImageContex
谢谢 此代码获取图形上下文并在其中绘制一条黑色线,根据保存的点与最后一个点之间的距离,到不同的位置
UIGraphicsBeginImageContext(self.frame.size);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), self.lastPoint.x, self.lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
mImgViewSig.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
最后一点是绘制到的最后一点,当前点是用户触摸到的点该页面不是found@AsaDickens说,它现在应该可以工作了。我会给你一些我用来制作签名托盘的代码,虽然它使用了一个空白的图像视图,但我认为你可以调整它以适应你的项目
UIGraphicsBeginImageContext(self.frame.size);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), self.lastPoint.x, self.lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
mImgViewSig.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();