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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -