开发者

iphone app slow using phonegap

I have develop a iphone/android drawing functionality application using phonegap. 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.

The size of www folder is less then 2MB. We are anot loading complex or heavy graphics.

Any suggestion would be开发者_JS百科 appreciated.


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


This is a limitation which is difficult to override. Doing this with web technologies bound to have this side effect. Only work around is to do this with 2D graphics.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜