Search code examples
swiftmultithreadingcore-graphicsmulti-touchuitouch

Multithreaded Coregraphics Drawing with Multitouch Actions, Swift


I'm developing an app that allows for multitouch inputs, and am having trouble drawing using drawRect in my UIView. When more than one finger is on the screen, I need to draw a rect that encompasses all the UITouch inputs. Is there any best practice around this, or a way to draw multiple rects at the same time to avoid drawing a larger part of the screen again and again?


Solution

  • UIView has a method setNeedsDisplay(_:) that takes a rectangle to invalidate. You can call that repeatedly to force update of multiple small rectangular areas. The system will ask the view to re-draw those rectangles.