0301——Notification 通知

注册消息

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(方法) name:@"消息名字" object:nil];

方法实现

-(void)方法:(NSNotification *)notfication{

    //获取传递的数据

    NSDictionary * dataDic = notfication.object; 

}

发布消息

[[NSNotificationCenter defaultCenter]postNotificationName:@"消息名字" object:传回的东西];

 

键盘的消息使用

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardDidChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];

方法实现

-(void)keyBoardDidChanged:(NSNotification *)notifi{

    //可以先打印notifi开看看有什么消息名字

    CGRect endRect = [[notifi.userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];

    ......//屏幕在键盘改变的时候重新布局

    [self.view layoutIfNeeded];   

}

原文地址:https://www.cnblogs.com/damonWq/p/5229706.html