0
点赞
收藏
分享

微信扫一扫

通知中心(loading...)


1. 添加通知中心时不要忘记写dealloc(即便是ARC)

假如一个button 添加了 nameButtonClick方法 点击就会触发通知中心

- (void)viewDidLoad {
     [super viewDidLoad];
     
不要忘记写dealloc)
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationClick:) name:@"friend" object:nil];
 }
 



- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (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

举报

相关推荐

0 条评论