Autolayout Constraint - Keyboard

后端 未结 4 1174
迷失自我
迷失自我 2020-12-22 19:05

Im stuck trying to animate a table view smoothly which has an autolayout contraint. I have a reference to the constraint \"keyboardHeight\" in my .h and have linked this up

4条回答
  •  情深已故
    2020-12-22 19:26

    Try it this way:

    self.keyboardHeight.constant = -height;
    [self.view setNeedsUpdateConstraints];
    
    [UIView animateWithDuration:animationDuration animations:^{
       [self.view layoutIfNeeded];
    }];
    

    Remember this pattern because this should be the correct way to update constraint-based layouts (according to WWDC). You can also add or remove NSLayoutConstraints as long as you call setNeedsUpdateConstraints after.

提交回复
热议问题