通知中心(loading...)
2016-03-05 18:17
218 查看
1. 添加通知中心时不要忘记写dealloc(即便是ARC)
- (void)viewDidLoad {
[super viewDidLoad];
// 添加通知中心(不要忘记写dealloc)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationClick:) name:@"friend" object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
假如一个button 添加了 nameButtonClick方法 点击就会触发通知中心
- (void)nameButtonClick:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"friend" object:self userInfo:nil];
CGRect rect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];// 键盘结束时候的rect
}
2. 给self.mainView
添加一个监听者 KeyPath:监听frame这个属性 options:监听新值的改变
[self.mainView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
当 self.mainView
的 frame
改变时会调用
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
- (void)viewDidLoad {
[super viewDidLoad];
// 添加通知中心(不要忘记写dealloc)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationClick:) name:@"friend" object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
假如一个button 添加了 nameButtonClick方法 点击就会触发通知中心
- (void)nameButtonClick:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"friend" object:self userInfo:nil];
CGRect rect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];// 键盘结束时候的rect
}
2. 给self.mainView
添加一个监听者 KeyPath:监听frame这个属性 options:监听新值的改变
[self.mainView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
当 self.mainView
的 frame
改变时会调用
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
相关文章推荐
- CF 427D 后缀数组
- 39. Combination Sum
- 关于低功耗蓝牙的连接参数更新
- Spring核心IOC容器实现分析
- ViewPager禁止滑动以及它与内层滑动控件水平方向上事件冲突的解决方法
- 深入学习JavaScript的AngularJS框架中指令的使用方法
- 极路由 openwrt 使用 SyncY 实现百度云同步
- 初识Hash
- js
- 反转链表
- Android 实现全屏 去掉标题栏
- spring mvc使用Maven配置Velocity
- 第一次作业
- Java第一周学习总结5311
- 客户端与服务端Post报文构造请求及Http Post与Get请求方法
- IntentService
- JQuery之ajax
- AJAX - 创建 XMLHttpRequest 对象
- JSP九大内置对象和四种属性范围解读
- 编程技巧