Keyboard 視圖隨鍵盤升高降低,keyboard視圖
(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotificationobject:nil];
}
- (void)keyboardWillShow:(NSNotification *)noti
{
//得到keyboard size
CGRect keyboardBounds;
[[noti.userInfovalueForKeyPath:UIKeyboardFrameEndUserInfoKey]getValue:&keyboardBounds];
CGRect frame ;
if (version<7.0) {
frame =CGRectMake(0,0, mainHeight,mainHeight-20);;
}else{
frame =CGRectMake(0,0, mainHeight,mainHeight);;
}
[UIViewbeginAnimations:nilcontext:NULL];
[UIViewsetAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:0.3f];
if (mainHeight<500) {
frame.origin.y -=110;
}else {
frame.origin.y -=25;
}
_backView.frame = frame;
[UIViewcommitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)noti
{
//得到keyboard size
CGRect keyboardBounds;
[[noti.userInfovalueForKeyPath:UIKeyboardFrameEndUserInfoKey]getValue:&keyboardBounds];
CGRect frame ;
if (version<7.0) {
frame =CGRectMake(0,0, mainHeight,mainHeight-20);;
}else{
frame =CGRectMake(0,0, mainHeight,mainHeight);;
}
[UIViewbeginAnimations:nilcontext:NULL];
[UIViewsetAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:0.3f];
_backView.frame = frame;
[UIViewcommitAnimations];
}