如何通过在焦点集中时将其移动到键盘顶部/视图中心来突出显示滚动视图中的焦点 UITextField
Posted
技术标签:
【中文标题】如何通过在焦点集中时将其移动到键盘顶部/视图中心来突出显示滚动视图中的焦点 UITextField【英文标题】:How to highlight the focussed UITextField in a scroll view by moving it to the top of the key board / center of the view when it was focussed 【发布时间】:2012-10-25 11:21:47 【问题描述】:在我看来,滚动视图中有 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;
但我的意图是当文本字段被聚焦时,该文本字段会向上移动到键盘顶部或视图中心
怎么做
【问题讨论】:
【参考方案1】:我在我的应用程序中使用TPKeyboardAvoiding,它似乎对我来说非常有效,不妨试试看。
【讨论】:
以上是关于如何通过在焦点集中时将其移动到键盘顶部/视图中心来突出显示滚动视图中的焦点 UITextField的主要内容,如果未能解决你的问题,请参考以下文章
在 Eclipse 控制台视图中,哪些键将焦点移动到按钮行?
将键盘选项卡焦点设置到页面顶部/使用 JavaScript / jQuery 重置键盘焦点