Continuous drawing in CGContext with drawRect

放肆的年华 提交于 2020-02-07 06:56:20

问题


My question might be answered somewhere but I just couldn't find solution after a long research.

I need to draw visually shapes (curves, lines, rectangles etc.) on iPhone one on top of the previous. I did that using CGContext to draw over an image and it's working fine. However in my app the drawing view resizes on device rotation and the lines become blurred because of the different image size. That's why I subclassed UIView and to call setNeedsDisplay from touchesMoved and touchesEnded. In drawRect I'm passing the point and... almost everything works OK. However I have two problems: 1. Every time drawRect is called it clears previous drawing and starts over so I can't add a new shape. 2. Second is followed by same thing - I can't make a curve as on every move drawRect is called and the previous point is dismissed and a line is added from the starting point to the current.

So am I doing the whole thing wrong and is there some other better approach to this.

Thanks in advance!

来源:https://stackoverflow.com/questions/9396558/continuous-drawing-in-cgcontext-with-drawrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!