在IB中设置好View的constraint后,将需要动态修改的constraint在代码中建立连接
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *inputViewBottom;
写键盘弹出和键盘隐藏的通知事件
- (void)keyboardWillShow:(NSNotification *)notification{
CGRect kbFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
self.inputViewBottom.constant = kbFrame.size.height;
[self.inputView needsUpdateConstraints];
}
- (void)keyboardWillHidden{
self.inputViewBottom.constant = 0;
[self.inputView needsUpdateConstraints];
}