ios - Auto Layout causes infinite layoutSubviews loop -
i'm puzzled this, when use auto layout on subview layoutsubview method loops infinitely.
all i'm doing is:
- (id)init { self = [super init]; if(self) { self.backgroundcolor = [uicolor graycolor]; _imageview = [[uiimageview alloc] init]; _imageview.translatesautoresizingmaskintoconstraints = no; [self addsubview:_imageview]; [self applyconstraints]; } return self; } -(void)applyconstraints { [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|-0-[_imageview]-0-|" options:0 metrics:nil views:nsdictionaryofvariablebindings(_imageview)]]; [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|-0-[_imageview]-0-|" options:0 metrics:nil views:nsdictionaryofvariablebindings(_imageview)]]; }
and causes infinite loop in layoutsubviews. when applyconstraints not called loop occurs, way stop happening setting 'translatesautoresizingmaskintoconstraints' yes.
has encountered/solved problem before?
update clarify, uiview subclass, used within view controller. view not use auto layout, instead it's frame set old fashioned way after initialization.
this might you.
layoutsubviews called
- when frame of view changes
- when view removed superview called on superview
- in uiscrollview, during scrolling.
- while adding view superview.
- during orientation change.
Comments
Post a Comment