UIView animated changes with auto layout constraints

前端 未结 3 1632
青春惊慌失措
青春惊慌失措 2020-12-23 14:29

Say that I have a project which looks like the following:

\"enter

There are tw

3条回答
  •  星月不相逢
    2020-12-23 15:12

    Try it as mentioned by shwet-solanki, but add the following line after changing the constraint:

    [self.view layoutIfNeeded];
    

    the IBAction would look like:

    - (IBAction)expandYellowBox:(id)sender {
    
    [UIView animateWithDuration:0.5
                     animations:^{
                         self.yellowBoxHeightConstraint.constant += 50;
                         [self.view layoutIfNeeded];
                     }];
    }
    

    Where yellowBoxHeightConstraint is the IBOutlet for height constraint of yellowBox. Hope this helps.

提交回复
热议问题