Re: [問題] keyboard擋住firstresponder
※ 引述《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
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章