IOS 鍵盤遮擋處理

2021-06-28 01:35:03 字數 937 閱讀 3997

1、textfield frame 根據textfield編輯狀態,動畫改變textfield frame;或用kvo監控鍵盤顯示及隱藏來改變textfield frame;

2、新增到scrollview  根據textfield編輯狀態,改變scrollview contentoffset;用kvo監控鍵盤顯示及隱藏改變scrollview contentoffset;

3、新增到tableview 根據textfield編輯狀態,改變tableview contentoffset;用kvo監控鍵盤高度變化及隱藏改變tableview contentoffset;

本文著重介紹第三種方法中的用kvo監控鍵盤高度變化及隱藏來控制tableview contentoffse:

1、新增及移除監控

[self registerforkeyboardnotifications];

} [[nsnotificationcenter defaultcenter] removeobserver:self];

}- (void)registerforkeyboardnotifications

2、鍵盤顯示及顯示後切換輸入法引起高度變化處理

- (void)keyboardwillshow:(nsnotification*)anotificaiton 

if (_keyboardinfo)

}}

3、鍵盤隱藏處理

- (void)keyboardwillhidden:(nsnotification*)anotificaiton

4、textfield 開始編輯時處理

- (bool)textfieldshouldbeginediting:(uitextfield *)textfield

ios 鍵盤遮擋

做ios開發時,難免會遇到輸入框被鍵盤遮掩的問題。上網上搜尋了很多相關的解決方案,看了很多,但是由衷的覺得太麻煩了。有的解決方案是將檢視上的所有的東西都新增到乙個滾動檢視物件 uiscrollview 中,然後滾動檢視實現輸入框不被軟鍵盤覆蓋,個人覺得此方案好是好,但是太過麻煩。有的解決方案是通過乙...

iOS 鍵盤遮擋處理辦法(不用鍵盤高度計算)

註冊觀察者觀察系統通知用以觀察鍵盤事件 鍵盤顯示事件 void keyboardwillshow nsnotification notification registerprotocolbutton 為最底部不想被遮擋的控制項 通過offset tempy registerprotocolbutto...

iOS之取消鍵盤遮擋

裝逼模式開啟 用uitextfielddelegate 來解決 鍵盤遮擋最常見的可能就是在登入介面了,無論有多少個textfiled,不論是在vc的任何位置。都有可能造成鍵盤撥出來時,遮擋輸入框。如圖1firstvideo.gif 兩個textfield在vc的下部如何讓鍵盤撥出的時候剛好在你點選t...