tags:

views:

1834

answers:

2

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

+4  A: 

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)

Adam Wright
I tried doing exactly that. No effect. Nuthin.In the subclass I overrode the setTransform: method thusly:- (void)setTransform:(CGAffineTransform)newValue { [super setTransform:newValue]; [self setNeedsDisplay];}
dugla
Apparently, I bit of code futzing now has setNeedsDisplay firing properly.
dugla
A: 

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.

Pascal