(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification *)noti
{
//得到keyboard size
CGRect keyboardBounds;
[[noti.userInfo
valueForKeyPath:UIKeyboardFrameEndUserInfoKey]getValue:&keyboardBounds];
CGRect frame ;
if (version<7.0) {
frame =
CGRectMake(0,
0, mainHeight,
mainHeight-20);;
}else{
frame =
CGRectMake(0,
0, mainHeight,
mainHeight);;
}
[UIView
beginAnimations:nil
context:NULL];
[UIView
setAnimationBeginsFromCurrentState:YES];
[UIView
setAnimationDuration:0.3f];
if (mainHeight<500) {
frame.origin.y -=
110;
}
else {
frame.origin.y -=
25;
}
_backView.frame = frame;
[UIView
commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)noti
{
//得到keyboard size
CGRect keyboardBounds;
[[noti.userInfo
valueForKeyPath:UIKeyboardFrameEndUserInfoKey]getValue:&keyboardBounds];
CGRect frame ;
if (version<7.0) {
frame =
CGRectMake(0,
0, mainHeight,
mainHeight-20);;
}else{
frame =
CGRectMake(0,
0, mainHeight,
mainHeight);;
}
[UIView
beginAnimations:nil
context:NULL];
[UIView
setAnimationBeginsFromCurrentState:YES];
[UIView
setAnimationDuration:0.3f];
_backView.frame = frame;
[UIView
commitAnimations];
}