//监听键盘
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHide:) name:UIKeyboardWillHideNotification object:nil];
#pragma mark 弹出键盘
-(void)keyBoardShow:(NSNotification *)notification
{
-(void)keyBoardShow:(NSNotification *)notification
{
//notification.userInfo获得用户的所有信息,userInfo是一个字典,根据key值 为UIKeyboardFrameEndUserInfoKey拿到键盘的frame的“字符串”,将这个字符串转成Rect
int y = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size.height;
[UIView animateWithDuration:0.3 animations:^{
bgImageView.center = CGPointMake(bgImageView.center.x, bgImageView.center.y-y/2);
}];
//将logo设置没
logoImageView.transform = CGAffineTransformMakeScale(0, 0);
}
#pragma mark 收键盘
-(void)keyBoardHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
bgImageView.center = self.view.center;
logoImageView.transform = CGAffineTransformMakeScale(1, 1);
}];
}
int y = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size.height;
[UIView animateWithDuration:0.3 animations:^{
bgImageView.center = CGPointMake(bgImageView.center.x, bgImageView.center.y-y/2);
}];
//将logo设置没
logoImageView.transform = CGAffineTransformMakeScale(0, 0);
}
#pragma mark 收键盘
-(void)keyBoardHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
bgImageView.center = self.view.center;
logoImageView.transform = CGAffineTransformMakeScale(1, 1);
}];
}