iPhone - setNeedsDisplay 不调用drawRect
我看过很多关于这个问题的帖子,但没有得到答案。我有一个控制器,它将视图添加到主窗口。控制器的视图有一个子视图,该子视图有一个drawRect。问题是,即使我调用 [self setNeedsDisplay],这个函数也永远不会被调用。
谢谢
I have seen many posts about this problem but didn't get an answer. I have a controller which view is added to the main window. The controller's view has a subview which has a drawRect. The problem is that this function is never called even if I call [self setNeedsDisplay].
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是
-(void)drawRect:(CGRect)rect
对吧?确保方法签名正确,并且即使不使用rect
参数,也不要省略它。-setNeedsDisplay
应该被称为子视图,而不是self
。另外,
-setNeedsDisplay
不会立即调用-drawRect:
。它仅刷新图形缓存,以便在下一次更新帧时强制调用-drawRect:
。It is
-(void)drawRect:(CGRect)rect
right? Make sure the method signature is correct, and you don't omit therect
argument even if you don't use it.-setNeedsDisplay
should be called the the subview, notself
.Also,
-setNeedsDisplay
won't call-drawRect:
immediately. It only flushes the graphics cache so that-drawRect:
is forced to be called in the next update of the frame.