0

I put a button in the corner of a sub view in the UIViewController. Now what I want is when the sub view increase its height, the button should be still at the corner. In the design I use autolayout as follow:

enter image description here

  • sub view (left, top, width, height)
  • button of the subview (left, bottom, right)

[UIView animateWithDuration:0.3 animations:^{

        //- Increase the subview's height
        CGRect frame = _subview.frame;
        frame.size.height = frame.size.height + 100;
        _subview.frame = frame;

        //- Update constraints
        [_subview layoutIfNeeded];
}];


But the button is still the same position.

chipbk10
  • 5,783
  • 12
  • 49
  • 85
  • 2
    You haven't updated the constraints of the green view. Under auto layout you can't set a frame. You need an outlet to that height constraint, which you update the constant for. – jrturton Apr 24 '14 at 16:19
  • 1
    See [this answer](http://stackoverflow.com/a/15752556/77567) for a demonstration of creating an outlet connected to a layout constraint, and modifying the constraint constant in code. – rob mayoff Apr 24 '14 at 16:21
  • Thanks. It seems that with autolayout, we don't pay attention on view.frame any more. You rescued my day. – chipbk10 Apr 24 '14 at 17:06

0 Answers0