在我看来,我在滚动视图中有 14 个文本字段。
要在键盘出现/消失时向上/向下移动视图,我已经设置了滚动视图框架大小
#pragma mark - Text field view delegate methods
- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
//To move the scroll view up to avoid keybord covers the text field
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
//scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y - 45), scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView setContentSize:CGSizeMake(200, 1100)];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField;
{
//To move the view down
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
[scrollView setContentSize:CGSizeMake(200, 900)];
//scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y + 45), scrollView.frame.size.width, scrollView.frame.size.height);
[UIView commitAnimations];
}
返回键盘专注于下一个字段和最后一个字段键盘辞职
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
if(textField == nameField) {
[emailText becomeFirstResponder];
} else if(textField == emailText) {
[mobileText becomeFirstResponder];
}
else if(textField == mobileText) {
[iPhoneText becomeFirstResponder];
}
else if(textField == iPhoneText.value) {
[companyText becomeFirstResponder];
}
else if(textField == companyText) {
[roleText becomeFirstResponder];
}
...
......
...........
else if(textField == lastfield) { // Last fiels
[textField resignFirstResponder];
}
return YES;
}
但我的意图是,当文本字段被聚焦时,文本字段会向上移动到键盘顶部或视图中心
怎么做