[英]how to draw lines quickly using coregraphics via time intervals in iphone
I am new to iphone programming. 我是iPhone编程的新手。
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.
我将NSTimer与0.01作为计时间隔。
I am using the following code to draw the lines. 我正在使用以下代码画线。 How can I draw those lines quickly using NSTimer?
如何使用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 the drawRect:
method. 如果要在视图中呈现此视图,则可能需要查看
UIView
子类,并将此绘图代码放置在drawRect:
方法内。
drawRect:
will have to re-draw the whole image each time, and may be called by the system whenever necessary. drawRect:
每次都必须重新绘制整个图像,并且可能在必要时由系统调用。 If you need to update it, call setNeedsDisplay:
on the view, and it'll redraw at the end of the run loop. 如果需要更新,请在视图上调用
setNeedsDisplay:
它将在运行循环结束时重绘。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.