Xcode6, iOS8 and (void) layoutSubviews

I have a custom UILabel that works fine on iOS6 and iOS7. But on iOS8, this label (void) layoutSubviews method is never called. I create this shortcut using initWithFrame, so this method must be called - and it called other versions of iOS. What happens with autoLayout in iOS8?

+7
uilabel autolayout ios8 xcode6 layoutsubviews
source share
3 answers

I just want to add this answer because the title of the question can lead to a lot of ppl here with similar problems (like me).

From iOS 8 to 8.0.2, LayoutSubviews calls are unreliable. They cannot be called ever or (in my case) called in a loop.

Despite the fact that you should not do this, it was rather safe to select material in LayoutSubviews, but with this incomprehensible (?!) Behavior this can lead to errors that complicate tracing.

I don’t know if all the problems fix 8, but there will be some time until the client devices starts 8.1 and they start 8.0.2 NOW

+5
source share

I had the same problem. In fact, layoutSubviews is no longer called for UILabel on iOS8, since Apple does not expect anyone to use it as a supervisor.

I use ReactiveCocoaLayout , so this can be done by subscribing to rcl_frameSignal or rcl_boundsSignal.

-(void)awakeFromNib { [ self.rcl_boundsSignal subscribeNext: ^( NSValue* boundsValue ) { //layout changed } ]; }

Or you can use a simple KVO to know when the frame was changed:

 -(void)dealloc { [ self removeObserver: self forKeyPath: @"layer.bounds" ]; } -(void)observeValueForKeyPath:( NSString* )keyPath ofObject:( id )object change:( NSDictionary* )change context:( void* )context { if ( [ keyPath isEqualToString: @"layer.bounds" ] ) { //layoutSubviews } else { [ super observeValueForKeyPath: keyPath ofObject: object change: change context: context ]; } } -(void)awakeFromNib { [ self addObserver: self forKeyPath: @"layer.bounds" options: NSKeyValueObservingOptionNew context: 0 ]; } 
+4
source share

The bug was fixed by Apple in iOS 8.1 (beta).

+2
source share

All Articles