最近在作一個聊天界面,要適配iOS全部屏幕。ide
之前的思路是鍵盤彈出的時候去改table 和輸入框的frame。spa
如今發現和autolayout的約束有衝突。code
搞了半天發現須要動態改Constraint。blog
- (void)keyboardDidShow:(NSNotification *)notification { CGRect kbFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; self.msgBoxBottomConstraint.constant = kbFrame.size.height; [self.messageBox needsUpdateConstraints]; } -(void)keyboardDidHide:(NSNotification*)notification { self.msgBoxBottomConstraint.constant = 0; [self.messageBox needsUpdateConstraints]; }