As Uli commented below, the proper way to do it is override layoutSubviews
and layout the imageViews there.
If, for some reason, you can't subclass and override layoutSubviews
, observing bounds
should work, even when being kind of dirty. Even worse, there is a risk with observing - Apple does not guarantee KVO works on UIKit classes. Read the discussion with Apple engineer here: When does an associated object get released?
original answer:
You can use key-value observing:
[yourView addObserver:self forKeyPath:@"bounds" options:0 context:nil];
and implement:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == yourView && [keyPath isEqualToString:@"bounds"]) {
// do your stuff, or better schedule to run later using performSelector:withObject:afterDuration:
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…