本文介绍了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].

谢谢

推荐答案

-(void)drawRect:(CGRect)rect 对吗?确保方法签名正确,并且即使不使用它也不要忽略 rect 参数。

It is -(void)drawRect:(CGRect)rect right? Make sure the method signature is correct, and you don't omit the rect argument even if you don't use it.

-setNeedsDisplay 应该称为子视图,而不是 self

-setNeedsDisplay should be called the the subview, not self.

此外, -setNeedsDisplay 不会调用 -drawRect:立即。它只刷新图形缓存,以便在下一次更新框架时强制调用 -drawRect:

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.

这篇关于iPhone-setNeedsDisplay不调用drawRect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 18:14