1,、當(dāng)鍵盤退下時(shí),,工具條依然留下,留給用戶作選擇,。這里工具條要成為發(fā)微博控制器view的一部分,。 2、我們需要監(jiān)聽鍵盤,,鍵盤發(fā)生變化時(shí),,會(huì)有相應(yīng)的通知。
// 4.監(jiān)聽鍵盤 // 鍵盤的frame(位置)即將改變, 就會(huì)發(fā)出UIKeyboardWillChangeFrameNotification // 鍵盤即將彈出, 就會(huì)發(fā)出UIKeyboardWillShowNotification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; // 鍵盤即將隱藏, 就會(huì)發(fā)出UIKeyboardWillHideNotification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 3,、鍵盤的處理 #pragma mark - 鍵盤處理 /** * 鍵盤即將隱藏 */ - (void)keyboardWillHide:(NSNotification *)note { // 1.鍵盤彈出需要的時(shí)間 CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
// 2.動(dòng)畫 [UIView animateWithDuration:duration animations:^{ self.toolbar.transform = CGAffineTransformIdentity; }]; } /** * 鍵盤即將彈出 */ - (void)keyboardWillShow:(NSNotification *)note { // 1.鍵盤彈出需要的時(shí)間 CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
// 2.動(dòng)畫 [UIView animateWithDuration:duration animations:^{ // 取出鍵盤高度 CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat keyboardH = keyboardF.size.height; self.toolbar.transform = CGAffineTransformMakeTranslation(0, - keyboardH); }]; } |
|