javascript - iphone 应用程序使用 phonegap 变慢

标签 javascript iphone android html cordova

我已经使用 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/

相关文章:

ios - 如何计算 IOS 7 上的蜂窝数据使用量

javascript - ng-grid 不适用于文件引用的单元格模板

javascript - 获取 CKEditor 4 中光标位置的父标签

javascript - 计时器在刷新时重置如何避免这种情况?

android - 在 Android 中捕获完整的日志

java - connect() 和 disconnect() 在哪里实现?

android - 在android中的listactivity中加载更多行

javascript - 制作一个 anchor 标记,点击时触发打印操作

iphone - 如何将自定义分隔线图像添加到 UITabBar?

php - iPhone 中的 RESTful Web 服务 : Data not inserted to database