开始编辑时滚动textField并出现键盘 [英] Scroll on textField when begin Editing and keyboard appear
问题描述
我有一个由UIImageView组成的viewController,它填充了整个视图以及位于视图中心的两个textField.所有这些都位于ScrollView内部. 我使用情节提要,并且禁用了自动布局. 当我单击textField从而打开键盘时,我希望将滚动条直接移到textField上.我该怎么办?
I've a viewController composed by an UIImageView that fills the whole view and two textField located at the center of the view. All this is located inside a ScrollView. I use Storyboard and I disabled the autolayout. When I click on a textField, and thus opens the keyboard, I'd like that the scroll is displaced directly on textField. How can I do that?
推荐答案
考虑将您的TextField出口命名为txtField
,然后实施
Consider that your TextField outlet is named txtField
then implement UITextField Delegate using
txtField.delegate = self;
考虑到您的ScrollView插座被命名为scrollView
.实现Textfield委托方法:
Considering that your ScrollView outlet is named scrollView
. Implement the Textfield Delegate method:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"%@",NSStringFromCGRect(textField.frame));
[scrollView scrollRectToVisible:textField.frame animated:YES];
}
希望这会有所帮助.
如果需要更多帮助,请告诉我.
Do let me know if you need more help.
这篇关于开始编辑时滚动textField并出现键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!