Re: [問題] keyboard擋住firstresponder

看板MacDev作者 (啵B勸-福.加油)時間12年前 (2013/06/03 17:47), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《whitefur (白毛)》之銘言: : 請問怎麼處理keyboard往上推出之後 : 擋住下面的textfield : 如果view不是scrollview的情況下 : 謝謝 可以在例如viewDidLoad的地方 用NSNotificationCenter接UIKeyboardWillShowNotification 在handler-selector function裡可以知道鍵盤大小(高度) - (void)你的handler:(NSNotification*)notification { NSValue* value = [[notification userInfo] valueForKey:\ UIKeyboardFrameBeginUserInfoKey]; CGFloat keyboardHeight = [value CGRectValue].size.height; } 然後再去把整個view的frame做調整: [UIView animateWithDuration:0.3f animations:^ { CGRect frame = self.view.frame; frame.origin.y -= 要移動的量; self.view.frame = frame; } ]; 編輯完了之後 如果是UITextField的話 就用UITextFieldDelegate function - (BOOL)textFieldShouldReturn:(UITextField*)textField { 跟上面移動self.view一樣的方法 然後 [textField resignFirstResponder]; return YES; } 以上~ ;) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.34.186.156
文章代碼(AID): #1Hh6OPID (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1Hh6OPID (MacDev)