0

我从移动的触摸调用 setNeedsDisplay (并且也尝试不从移动的触摸调用,而是从 0.05 计时器调用)并且 drawrect 方法总是滞后。他们无论如何要改变这一点?我在drawrect中做了很多绘图,但我不知道解决滞后的解决方案。即使以 1.0 的间隔调用计时器,当计时器调用选择器时它仍然滞后。此外,我没有泄漏(我使用 Xcode 分析功能进行了检查)。请帮忙!!

编辑:我正在调用 setNeedsDisplay,而不是从我的计时器/方法中调用 drawRect

编辑:似乎无论核心图形在哪里进行大量绘图,它总是滞后。我很肯定我没有内存泄漏,我什至创建了另一个绘画应用程序并且它滞后(对此有什么解决方法??请帮帮我)

4

4 回答 4

4

Slightly edited transcript of comments on one of the other answers:

I am drawing a color a hue based color picker (in draw rect a line for each hue value is drawn)

… Are you drawing 360 rectangles?

Yes, I am ….

I draw the images of 360 rectangles of different colors into the image of one UIImageView. than I release the rectangles. (I use a for loop for the rectangle allocation/releasing)

So, you are doing this 360 times:

  1. Create an image.
  2. Draw a rectangle into this image. (Or not, if step 1 loads the image from a file.)
  3. Draw that image into another image.
  4. Release the image.

And then you pass the image that you drew all the smaller images into to a UIImageView for the actual display?

It sounds like you're trying to cache this in the image, which should help after the first time if you do it right, but this doesn't need to be slow in the first place.

You already have a custom view. Drop the image view, and cut out all this rectangle-drawing (or image-drawing) code. If you have image files with the individual colored rectangles, delete them.

In your view's drawRect:, create a gradient and draw that. Your drawRect: will be three lines long and should be much, much, much faster.

于 2011-10-03T02:21:39.907 回答
2

drawRect你不应该明确地打电话。改为使用setNeedsDisplay,系统准备就绪时将执行绘图。

编辑:基于您已经在这样做的事实。你的问题是你的 drawRect 太慢了。你想画什么?

于 2011-10-02T14:48:31.623 回答
2

我正在从触摸移动中调用drawrect

不要那样做。

(并且也尝试过不从移动的触摸调用,而是从 0.05 计时器调用)

不要那样做。

and the drawrect method is always laggy. Is their anyway to change this? I am doing a lot of drawing in drawrect but I have no idea for a solution to fix the lag. Even when the timer was called at a 1.0 interval than it still lagged when the timer called the selector. Also, I have no leaks (I checked using Xcode analyze feature ). Please help!!

Yes!

于 2011-10-02T14:50:33.623 回答
0

If you can figure out which parts of the screen needs change, you can call setNeedsDisplayInRect to speed it up by just redrawing the changed rect instead of the whole screen.

You can also run a background thread to prepare frames in a buffer and use that to draw on screen. It depends on the kind of drawing you are doing. Here is a blog post I found on this topic.

Or you can use OpenGL ES to draw.

于 2011-10-02T15:11:33.880 回答