OGeek|极客世界-中国程序员成长平台

标题: objective-c - IOS 5 SetNeedsDisplayInRect 导致全屏无效 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:43
标题: objective-c - IOS 5 SetNeedsDisplayInRect 导致全屏无效

我注意到IOS5第一次调用SetNeedsDisplayInRect时,会导致设备刷新全屏。 这与以前的 IOS 版本不同。

在我正在开发的应用程序中,我有一组需要绘制的对象(主要是矩形,具有不同的线条大小)。 如果我只想重绘几个矩形,我将对象添加到“更新”-Array 并调用 SetNeedsDisplayInRect 以使矩形区域无效。

在我的 drawRect 方法中,我这样确定,要么绘制完整的对象数组,要么只绘制“更新数组”:

BOOL boolDrawFullScreen = CGRectEqualToRect(rect, self.frame);

if (boolDrawFullScreen)
//draw all the objects
else
//draw just the objects within the update-array

在我使用 IOS5 对其进行测试之前,它一直运行良好。 实际上它仍然有效,但不是第一次调用 SetNeedsDisplayInRect 时:--> CGRectEqualToRect 总是返回是。

为什么会这样??我做错了什么?

任何建议都非常感谢! 谢谢

汤姆



Best Answer-推荐答案


记录了此行为 here在 QA1708 提高 iOS 上的图像绘制性能

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:.

因此,如果您的屏幕子矩形应该独立于屏幕的其余部分进行更新,您似乎会想要使用 subview 。

关于objective-c - IOS 5 SetNeedsDisplayInRect 导致全屏无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8472500/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4