注册消息
[[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(keyBoardDicChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];
方法实现
-(void)keyBoardDicChanged:(NSNotification *)notifi{
//可以先打印notifi开看看有什么消息名字
CGRect endRect = [[notifi.userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
......//屏幕在键盘改变的时候重新布局
[self.view layoutIfNeeded];
}