I am new to iphone programming.
In my app, I have to draw the lines very quickly according to my requirements. I am taking NSTimer with 0.01 as timing interval.
I am using the following code to draw the lines. How can I draw those lines quickly using NSTimer?
UIGraphicsBeginImageContext(bgImage.frame.size);
[bgImage.image drawInRect:CGRectMake(0, 0, bgImage.frame.size.width, bgImage.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),5);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),([UIColor blueColor]).CGColor);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endPoint.x, endPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
bgImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
endpoint=startpoint;
can anybody help me?
If you want to present this in a view, you probably want to look at subclassing
UIView, and placing this drawing code inside thedrawRect:method.drawRect:will have to re-draw the whole image each time, and may be called by the system whenever necessary. If you need to update it, callsetNeedsDisplay:on the view, and it’ll redraw at the end of the run loop.