Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Force Redrawing (drawRect) of a SubView When it Changes Dimensions?

I have a UIView that contains a row of subclasses of UIView. The subclass has overridden drawRect: and has set contentMode = UIViewContentModeRedraw.

As the user squashes and stretches the parent container the child views squash and stretch. As the shape change occurs I would like to have drawRect called repeatedly to change the contents of the child views. So far I have been unsuccessful. What is the correct way to do this?

Cheers,

Doug

like image 827
dugla Avatar asked Sep 17 '09 23:09

dugla


2 Answers

In Cocoa, you rarely (if ever) call drawRect - you just mark the region or view as needing update, and it will be scheduled for redrawing. This allows redraws for multiple invalidations to be collapsed together.

For Cocoa Touch, you want either [view setNeedsDisplay], or setNeedsDisplayinRect:(CGRect)

like image 172
Adam Wright Avatar answered Nov 11 '22 15:11

Adam Wright


You need to call [view setNeedsLayout], this should cause the subviews to receive a drawRect: call if the layout changes. I haven't tested this, however.

like image 33
Pascal Avatar answered Nov 11 '22 14:11

Pascal