当他们出现的键盘,当键盘消失向下移动的模式对话框被移动了。
直到我转动iPad的所有的罚款。 除了标准的任何其他方向这是行不通的。 当iPad正在模态对话框转头向下移动,当键盘时,键盘消失的不降反升出现,而不是一直上升。
这是我使用键盘出现时定位模式对话框的代码/消失。
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.view.superview.frame = CGRectMake(self.view.superview.frame.origin.x, 140, self.view.superview.frame.size.width, self.view.superview.frame.size.height);
}
}];
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
[UIView animateWithDuration:0.4 animations:^ {
self.view.superview.frame = CGRectMake(self.view.superview.frame.origin.x, 212, self.view.superview.frame.size.width, self.view.superview.frame.size.height);
}
}];
}
代替设置框的,使用CGAffineTransformTranslate,例如像这样:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.view.superview.transform = CGAffineTransformTranslate(self.view.superview.transform,0,72);
}
}];
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
[UIView animateWithDuration:0.4 animations:^ {
self.view.superview.transform = CGAffineTransformTranslate(self.view.superview.transform,0,-72);
}
}];
}
你应该尝试使用键盘声明:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeDismissed:) name:UIKeyboardWillHideNotification object:nil];
然后在选择器调节框架。 不textFieldDidBeginEditing / textFieldDidEndEditing。
- (void)keyboardWasShown:(NSNotification *) notification {
NSDictionary *info = [notification userInfo];
NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
keyboardHeight = MIN(keyboardSize.height, keyboardSize.width);
// set new frame based on keyboard size
- (void)keyboardWillBeDismissed: (NSNotification *) notification{
[UIView animateWithDuration:0.4 animations:^{
// original frame
}];
}
文章来源: Moving dialog up when keyboard present works except when ipad is turned around