简体   繁体   English

iPhone应用程序使用phonegap缓慢

[英]iphone app slow using phonegap

I have develop a iphone/android drawing functionality application using phonegap. 我已经使用phonegap开发了iphone / android绘图功能应用程序。 On touch start and touch move, app can draw lines upon a canvas(Context). 在触摸开始和触摸移动时,应用程序可以在画布(上下文)上绘制线条。 Drawing on line is very slow.Even loading time of app is very slow.(The Splash screen display itself minimum 6-8 secs. 在线绘制非常慢,甚至应用程序的加载时间也非常慢(启动屏幕显示本身至少需要6-8秒。

The size of www folder is less then 2MB. www文件夹的大小小于2MB。 We are anot loading complex or heavy graphics. 我们不会加载复杂或繁重的图形。

Any suggestion would be appreciated. 任何建议,将不胜感激。

This is a limitation which is difficult to override. 这是一个很难克服的限制。 Doing this with web technologies bound to have this side effect. 使用Web技术这样做必然会产生副作用。 Only work around is to do this with 2D graphics. 唯一的解决方法是使用2D图形。

I'm not really sure if this is what you mean, but to get it to draw in a usual manner, this is what your code should look like: 我不确定这是否是您的意思,但是要以一种通常的方式绘制它,这就是您的代码应为:

Note you can change the settings of your 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM