假设我的 View 中有两个非常小的区域需要重新绘制。一个位于左上角,另一个位于右下角。我可以使用它们的坐标将包含两个区域的单个大型 CGRect 传递给 setNeedsDisplayInRect,但这最终会包括许多不需要重绘的其他区域。
因此,另一种选择是简单地将包含 CGRect 的个体传递给 setNeedsDisplayInRect,一个接着一个,即
[self.view setNeedsDisplayInRect:rectForArea1]
[self.view setNeedsDisplayInRect:rectForArea2]
哪个通常会更快?最小化最终调用drawRect:的次数,或者最小化它必须重绘的屏幕区域量,即使它必须重绘两次?
最佳答案
没关系。如上所述here ,iOS 将始终更新整个 View ,与您传递给 setNeedsDisplayInRect 的矩形无关:
Note that, because of the way that iPhone/iPod touch/iPad updates its screen, the entire view will be redrawn if you call -setNeedsDisplayInRect: or -setNeedsDisplay:.
关于iOS:当 View 中有两个小的、不相邻的区域需要重绘时,调用 setNeedsDisplayInRect 两次会更快吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6800262/