从移动的触摸调用drawrect时,CoreGraphics不滞后的任何可能方法是什么? [英] Any possible way for CoreGraphics to not lag when drawrect is being called from touches moved?

查看:103
本文介绍了从移动的触摸调用drawrect时,CoreGraphics不滞后的任何可能方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从移动的触摸调用setNeedsDisplay(并且还尝试了从移动的触摸而不是从0.05计时器调用),而drawrect方法总是很麻烦.反正他们改变了吗?我在drawrect中进行了大量绘图,但是我不知道解决滞后的解决方案.即使以1.0个间隔调用计时器,但当计时器调用选择器时,它仍然滞后.另外,我没有泄漏(我使用Xcode分析功能进行了检查).请帮忙!

I am calling setNeedsDisplay from touches moved (and have also tried not calling from touches moved, but instead from a 0.05 timer) 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!!

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

I am calling setNeedsDisplay, not drawRect from my timer/method

似乎无论核心图形在哪里执行很多绘制工作,它总是滞后.我很肯定我没有内存泄漏,甚至创建了另一个绘画应用程序并且它滞后了(此问题的解决方法是什么?请帮助我)

It seems that wherever core graphics does somethings with a lot of drawing it always lags. I am positive I have no memory leaks and I even created another painting app and it lags (what is the fix to this?? Please help mee)

推荐答案

对其他答案之一的评论的成绩单进行了轻微

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)

…您要绘制360个矩形吗?

… Are you drawing 360 rectangles?

是的,我是…….

我将360种不同颜色的矩形的图像绘制到一个UIImageView的图像中.比我释放矩形(我使用for循环进行矩形分配/释放)

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)

因此,您正在执行360次:

So, you are doing this 360 times:

  1. 创建图像.
  2. 在此图像中绘制一个矩形. (或者不,如果第1步从文件加载图像.)
  3. 将该图像绘制到另一幅图像中.
  4. 释放图像.

然后将绘制了所有较小图像的图像传递到UIImageView进行实际显示?

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.

在视图的drawRect:中,创建渐变绘制.您的drawRect:长为三行,并且应该快得多.

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.

这篇关于从移动的触摸调用drawrect时,CoreGraphics不滞后的任何可能方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆