iOS開發-鍵盤通知
iOS開發-鍵盤通知
4種常用通知
UIKeyboardWillShowNotification、UIKeyboardDidShowNotification、UIKeyboardDidHideNotification、UIKeyboardDidHideNotification
註冊與解除
addObserver與removeObserver需要在對應的生命週期中成對出現。即有“新增”有“刪除”。
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// 註冊鍵盤通知
// 即將顯示
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
// 顯示
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (keyboardDidShowNotification:) name:UIKeyboardDidShowNotification object:nil];
// 即將隱藏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardDidHideNotification object:nil];
// 隱藏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHideNotification:) name:UIKeyboardDidHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
// 接觸鍵盤通知
// 即將顯示
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
// 顯示
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
// 即將隱藏
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
// 隱藏
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
}
- (void) keyboardWillShowNotification: (NSNotification *)notif{
NSLog(@"鍵盤即將顯示");
}
- (void) keyboardDidShowNotification: (NSNotification *)notif{
NSLog(@"鍵盤顯示");
}
- (void) keyboardWillHideNotification:(NSNotification *)notif{
NSLog(@"鍵盤即將隱藏");
}
- (void) keyboardDidHideNotification:(NSNotification *)notif{
NSLog(@"鍵盤隱藏");
}
相關文章
- 處理鍵盤通知
- iOS上開發的一個安全鍵盤iOS
- iOS 本地通知NSNotificationcenter --- iOS 開發iOS
- UIKeyboard鍵盤相關知識點-IOS開發UIiOS
- Swift開發---UITextView通過鍵盤Return回收鍵盤SwiftUITextView
- iOS 切換鍵盤iOS
- ios 修改鍵盤returniOS
- iOS開發常用快捷鍵iOS
- 利用鍵盤鉤子開發按鍵發音程式
- 利用鍵盤鉤子開發按鍵發音程式 (轉)
- iOS安全攻防(八):鍵盤快取與安全鍵盤iOS快取
- iOS開發之自定義表情鍵盤(元件封裝與自動佈局)iOS元件封裝
- iOS 鍵盤框架IQKeyboardManager使用iOS框架
- MOBIM ios 表情鍵盤排版方法iOS
- iOS開發--通知,代理,KVO的區別,以及通知的多執行緒問題iOS執行緒
- 驅動開發 鍵盤過濾驅動程式-- 傳統的鍵盤過濾
- 安卓開發 點選空白處收起鍵盤安卓
- 純鍵盤開發實戰(MouselessProgramming)
- iOS 自定義鍵盤字母按鈕iOS
- iOS表情鍵盤的完整實現iOS
- Android開發之道(7)響應鍵盤事件Android事件
- ios pop介面 鍵盤彈起又收回iOS
- 如何巧妙應對iOS鍵盤難題?iOS
- touchpad 開源鍵盤
- Android開發,在Fragment中,隱藏或關閉軟鍵盤(虛擬鍵盤)的方法AndroidFragment
- iOS 遠端通知iOS
- iOS 通知中心(NSNotificationCenter)iOS
- iOS: 讓鍵盤消失的的4種方法iOS
- iOS 文字輸入框隨鍵盤上移iOS
- Redis鍵空間通知Redis
- 前端開發:用鍵盤為生活敲出歡快節奏前端
- 修復蘋果iOS 原生鍵盤遮擋input框蘋果iOS
- 安卓和ios鍵盤擋住輸入內容安卓iOS
- iOS textField鍵盤彈出/收起 自動上下移iOS
- Xamarin iOS教程之鍵盤的使用和設定iOS
- iOS 通知擴充套件iOS套件
- nagios mail告警通知iOSAI
- iOS本地通知(推送)iOS