鍵盤上移問題

1、輸入框監聽UIControlEventEditingDidBegin事件,當用戶開始輸入時,將整個view上移。

輸入框監聽UIControlEventEditingDidEnd事件,當用戶結束輸入時,將整個view下移,恢復到原位置。

[textfield addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];

[textfield addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventEditingDidEnd];

通過tag值來確定每個textfield是否響應

2//鍵盤監聽

[[NSNotificationCenter

defaultCenter] addObserver:self

selector:@selector(keyboardWillChangeFrame:)

name:UIKeyboardWillChangeFrameNotification object:nil];

- (void)keyboardWillChangeFrame:(NSNotification *)notification

{

CGRect isUpflag;

[[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&isUpflag];

NSDictionary *info = [notification userInfo];

CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

[UIView animateWithDuration:0.25 animations:^{

showView.center = CGPointMake(showView.center.x, self.view.center.y - kbSize.height);

}];

}

kbSize.height可以獲取鍵盤的高度

原文地址 :http://blog.csdn.net/pzhtpf/article/details/9857857

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容