我已经使用 phonegap 开发了一个 iphone/android 绘图功能应用程序。在触摸开始和触摸移动时,应用程序可以在 Canvas (上下文)上画线。 在线绘图非常慢。甚至应用程序的加载时间也非常慢。(启动画面显示本身至少 6-8 秒。
www 文件夹的大小小于 2MB。我们不会加载复杂或繁重的图形。
如有任何建议,我们将不胜感激。
最佳答案
我不太确定这是否是您的意思,但是为了以通常的方式绘制它,您的代码应该如下所示:
请注意,您可以更改上下文的设置。
@synthesize canvas, drawing; //Both UIImageViews
CGPoint touchPrev;
CGPoint touchLoc;
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
touchPrev = [touch locationInView:self.view];
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
touchLoc = [touch locationInView:self.view];
UIGraphicsBeginImageContext(canvas.frame.size);
[canvas.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 8);
CGContextSetRGBStrokeColor(context, 0.8, 0, 0, 1);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), touchLoc.x, touchLoc.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), touchPrev.x, touchPrev.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
canvas.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
touchPrev = touchLoc;
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
touchPrev = touchLoc;
}
关于javascript - iphone 应用程序使用 phonegap 变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7426056/