【发布时间】:2013-02-24 00:27:27
【问题描述】:
我正在尝试设置自定义 UIView 类的背景颜色。该课程还使用drawRect:method 进行石英绘图。
由于在下次重绘视图之前不会更改背景颜色,因此我在调用 setNeedsDisplay 之前更改了 UIView 的 backgroundColor 属性。我设置了一个UIActivityIndicatorView 以在视图重绘时进行动画处理。
self.backgroundColor = theColor;
[indicator startAnimating];
[self performSelectorInBackground:@selector(setNeedsDisplay) withObject:nil];
指标在setNeedsDisplay 的末尾停止。 theColor 每次我需要调用它时都会改变。
假设我有一个耗时的setNeedsDisplay 进程。我想设置背景并保留指示器动画。目前,更改backgroundColor 调用setNeedsDisplay,但在performSelectorInBackground 方法运行之前甚至不会更改背景颜色!因此,我的应用程序挂起,并且没有任何指标动画。
我该如何处理这个排序问题?谢谢。
编辑:我的意思是我的drawrect: 可能很耗时。
【问题讨论】:
-
setNeedsDisplay不耗时,它是drawRect:。但无论如何你都不应该打电话给drawRect:。
标签: ios objective-c cocoa performselector setneedsdisplay