[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
- (void)keyboardWasShown:(NSNotification *)aNotification{
CGRect keyBoardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSLog(@"%f",keyBoardFrame.size.height);
[self changeViewFrame:keyBoardFrame.size.height];
}
- (void)keyboardWillBeHidden:(NSNotification *)notif{
NSDictionary *info = [notif userInfo];
NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
[self changeBackFrame];
NSLog(@"%f",keyboardSize.height);
}
-(void)changeViewFrame:(CGFloat)height{
[UIView animateWithDuration:0.3 animations:^{
CGRect frame=self.view.frame;
frame.origin.y=-height+kScreenSize.height/20-kScreenSize.height/14.23;
self.view.frame=frame;
}];
}
-(void)changeBackFrame{
[UIView animateWithDuration:0.3 animations:^{
CGRect frame=self.view.frame;
frame.origin.y=0.0;
self.view.frame=frame;
}];
}