iOS开发-键盘通知
来源:互联网 发布:护眼仪有用吗 知乎 编辑:程序博客网 时间:2024/05/22 02:21
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(@"键盘隐藏");}
1 0
- iOS开发-键盘通知
- ios SDK开发之键盘通知
- iOS键盘通知
- 处理iOS键盘通知
- iOS-键盘通知
- iOS键盘监察通知
- iOS开发之通知机制——UIDevice通知、键盘通知
- iOS开发(5)动态监听键盘通知
- ios 键盘高度改变通知
- iOS 系统 键盘的通知
- IOS键盘通知中心方法
- iOS--利用通知监听键盘
- IOS: iPhone键盘通知与键盘定制
- IOS: iPhone键盘通知与键盘定制
- IOS: iPhone键盘通知与键盘定制
- ios键盘通知和自定义键盘
- IOS: iPhone键盘通知与键盘定制
- ios键盘通知和自定义键盘
- 灰度世界算法(Gray World Algorithm)
- C++ STL vector
- js学习笔记
- final、finally、finalize
- STM32的BOOT0和BOOT1
- iOS开发-键盘通知
- 开源集锦(八)GitHub开源控件(四)
- HDU 5755 Gambler Bo(高斯消元裸题)——2016 Multi-University Training Contest 3
- es6箭头函数
- 读懂 Linux中的 diff
- 微信热修复开源库 Tinker imitator 原理篇
- C/C++内存泄漏及检测
- CS231n 学习笔记(2)——神经网络 part2 :线性分类器,SVM
- HDU 5762 Teacher Bo (水题)