【问题标题】:iphone app slow using phonegapiphone应用程序使用phonegap速度慢
【发布时间】:2011-09-15 04:58:53
【问题描述】:

我已经使用 phonegap 开发了一个 iphone/android 绘图功能应用程序。在触摸开始和触摸移动时,应用程序可以在画布(上下文)上绘制线条。 在线绘图很慢。甚至应用程序的加载时间也很慢。(启动画面显示本身至少6-8秒。

www 文件夹的大小小于 2MB。我们不会加载复杂或繁重的图形。

任何建议都将不胜感激。

【问题讨论】:

  • 您可以向我们提供有关该应用程序的更多详细信息。大小(以 kb 为单位)、加载的图像等。我注意到 Phonegap 在复杂/繁重的图形应用程序上往往反应迟钝。
  • www 文件夹的大小小于 2MB。我们没有加载复杂或繁重的图形。绘图功能最初很慢,但如果用户继续使用应用程序,那么一段时间后应用程序的绘图功能在某种程度上可以正常工作。

标签: javascript iphone android html cordova


【解决方案1】:

我不确定这是否是您的意思,但要让它以通常的方式绘制,您的代码应该是这样的:

请注意,您可以更改 Context 的设置。

@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;
}

【讨论】:

  • 您好 Fernando,我在我的应用程序中使用 html5/Javascript(使用 phonegap 框架)。上述代码属于Core Objective C。
【解决方案2】:

这是一个难以克服的限制。使用 Web 技术执行此操作必然会产生这种副作用。唯一的解决方法是使用 2D 图形来执行此操作。

【讨论】:

  • 嗨 Rahul,我们已经在使用 2D 图形。 canvas = document.getElementById("canvas"); canvas.width = window.innerWidth-5; canvas.height = window.innerHeight -5; ctx = canvas.getContext("2d"); ctx.fillStyle = "黑色"; ctx.beginPath(); ctx.lineWidth = 35; ctx.strokeStyle = '白色'; ctx.lineCap = "圆形"; ctx.lineJoin = "圆形"; canvas1.ontouchstart = function(e) { // 初始化 x 和 y } canvas1.ontouchmove = function(e) { // 做绘图功能 }
  • @neil,您使用的是 javascript,我的意思是 QuartzCore 或 Core2D iOS 框架
  • 我正在使用 html5 canvas/context 绘制多条线。在 iphone 模拟器中绘图功能非常快,但在真实设备上却很慢。
  • iPhone 模拟器不是真正的性能参数。由于它在 Macbook 上运行(更多 RAM,更多处理器),因此无法显示真实图片。我使用 javascript 创建了基于画布的多个应用程序,由于 WebView 的限制,性能与本机框架相比永远不同。有趣的是,与 UIWebView 相比,如果你创建一个 webapp 并在 safari 中打开它,性能会更好。
  • 我们的应用程序将是基于 Web 的编码并封装在 www 文件夹中。Phonegap 允许将 Web 应用程序转换为原生应用程序。市场上有很多具有高速性能的phonegap应用程序。为什么我们的绘图应用这么慢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-24
  • 2012-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多