我使用phonegap开发了一个iphone/android绘图功能应用程序。在触摸开始和触摸移动时,应用程序可以在画布(上下文)上绘制线条。在线绘图是非常slow.Even的应用程序加载时间非常慢。(闪屏显示本身最少6-8秒。
www文件夹的大小小于2MB。我们不是在加载复杂或沉重的图形。
任何建议都将不胜感激。
发布于 2011-09-15 13:45:24
我不太确定这是否是你的意思,但为了让它以通常的方式绘制,你的代码应该是这样的:
注意:您可以更改上下文的设置。
@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;
}
发布于 2011-09-15 13:46:05
这是一个很难克服的限制。用web技术来做这件事肯定会有这个副作用。唯一的解决办法是使用2D图形来完成此操作。
https://stackoverflow.com/questions/7426056
复制相似问题