usando el argumento rect para el método drawRect en UIView personalizado

How can I possibly use the rect argument passed in drawRect calls, am sure whenever setNeedsDisplayInRect is passed, drawRect method is called for particular region. for now I redraw the text and shapes for entire frame and not constraining to the rect part that needs to be redrawn and I have no idea on how effectively can I use the rect param. Any insights on this will be helpful.

preguntado el 28 de agosto de 12 a las 08:08

1 Respuestas

The rect is the region to redraw. In some cases UIKit will redraw only a "dirty" region of your view. You can optimize your code to detect that some of the drawing would occur outside this rect by using CGRectContainsPoint() and therefore not do it.

Respondido 28 ago 12, 10:08

Thanks, it works, just for clarification, since my draw strings uses rect, i will have to use CGRectContainsRect() instead of CGRectContainsPoint(), isn't it? also will that affect performance if used for table cell views - amigos

You can use CGRectContainsRect() for strings. There is a potential speed improvement depending on Apple's implementation of the cell drawing code. You can do simple refresh and scroll tests, and put counters to benchmark if there is a benefit. In my opinion, unless there is some big rendering on your cells, that performance gain would be minimal. - Resh32

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.