[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardFrameChange:)
name:UIKeyboardWillChangeFrameNotification object:nil];
- (void)keyboardFrameChange:(NSNotification *)note
{
// 获取键盘弹出的动画时间
CGFloat durtion = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
// 获取键盘的frame
CGRect frame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
if (frame.origin.y == self.view.height) { // 没有弹出键盘
[UIView animateWithDuration:durtion animations:^{
self.label.transform = CGAffineTransformIdentity;
}];
}else{ // 弹出键盘
// 工具条往上移动258
[UIView animateWithDuration:durtion animations:^{
self.label.transform = CGAffineTransformMakeTranslation(0, -frame.size.height);
}];
}
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}