您的位置:首页 > 其它

通知中心(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: