鍵盤上移問題

1、輸入框監(jiān)聽UIControlEventEditingDidBegin事件,當(dāng)用戶開始輸入時,將整個view上移。

輸入框監(jiān)聽UIControlEventEditingDidEnd事件,當(dāng)用戶結(jié)束輸入時,將整個view下移,恢復(fù)到原位置。

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

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

通過tag值來確定每個textfield是否響應(yīng)

2//鍵盤監(jiān)聽

[[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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容