IPhone应用程序缓慢使用phonegap

iphone app slow using phonegap

本文关键字:phonegap 缓慢 应用程序 IPhone      更新时间:2023-09-26

我使用phonegap开发了一个iphone/android绘图功能应用程序。在触摸开始和触摸移动时,应用程序可以在画布上绘制线条(Context)。在网上画画很慢。甚至应用程序的加载时间也很慢。(启动画面显示自己至少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;
}

这是一个很难克服的限制。在网络技术上这样做必然会有这样的副作用。唯一的解决办法是在2D图形中这样做。