首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用phonegap的iphone应用程序运行缓慢

使用phonegap的iphone应用程序运行缓慢
EN

Stack Overflow用户
提问于 2011-09-15 12:58:53
回答 2查看 2K关注 0票数 1

我使用phonegap开发了一个iphone/android绘图功能应用程序。在触摸开始和触摸移动时,应用程序可以在画布(上下文)上绘制线条。在线绘图是非常slow.Even的应用程序加载时间非常慢。(闪屏显示本身最少6-8秒。

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

任何建议都将不胜感激。

EN

回答 2

Stack Overflow用户

发布于 2011-09-15 13:45:24

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

注意:您可以更改上下文的设置。

代码语言:javascript
运行
复制
@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;
}
票数 0
EN

Stack Overflow用户

发布于 2011-09-15 13:46:05

这是一个很难克服的限制。用web技术来做这件事肯定会有这个副作用。唯一的解决办法是使用2D图形来完成此操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7426056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档