Ios 当键盘出现并启用滚动时,文本字段向上移动
我正在使用带有scrollview的textfield。每当键盘出现时,滚动被启用,文本字段向上移动。但有一个问题,如果我滚动我的文本字段,然后点击另一个文本字段,它不会向上移动Ios 当键盘出现并启用滚动时,文本字段向上移动,ios,uiscrollview,uitextfield,Ios,Uiscrollview,Uitextfield,我正在使用带有scrollview的textfield。每当键盘出现时,滚动被启用,文本字段向上移动。但有一个问题,如果我滚动我的文本字段,然后点击另一个文本字段,它不会向上移动 请提出建议。如果您使用的是scrollView,这将最适合您。使用。它很容易使用 将TPKeyboardAvoidingScrollView.m和TPKeyboardAvoidingScrollView.h源文件放入项目中,将UIScrollView弹出到视图控制器的xib中,将滚动视图的类设置为TPKeyboardA
请提出建议。如果您使用的是scrollView,这将最适合您。使用。它很容易使用
将
TPKeyboardAvoidingScrollView.m
和TPKeyboardAvoidingScrollView.h
源文件放入项目中,将UIScrollView
弹出到视图控制器的xib中,将滚动视图的类设置为TPKeyboardAvoidingScrollView
,并将所有控件放在该滚动视图中。您也可以通过编程方式创建它,无需使用xib-只需使用TPKeyboardAvoidingScrollView
作为顶级视图。您可以将文本字段坐标系转换为滚动视图坐标系。使用下面的代码
-(void)rearrangeView{
// previous
if (txtActiveField == txtUsername) {
CGPoint pt;
CGRect rc = [txtUsername bounds];
rc = [txtUsername convertRect:rc toView:scrollViewLogin];
pt = rc.origin;
pt.x = 0;
pt.y -= 40;
[scrollViewLogin setContentOffset:pt animated:YES];
}
else if (txtActiveField == txtPassword) {
// [self.txtEmail becomeFirstResponder];
CGPoint pt;
CGRect rc = [txtPassword bounds];
rc = [txtPassword convertRect:rc toView:scrollViewLogin];
pt = rc.origin;
pt.x = 0;
pt.y -= 40;
[scrollViewLogin setContentOffset:pt animated:YES];
}
}
#pragma mark- UITextField Delegate
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
txtActiveField = textField;
//txtActiveField.placeholder = @"";
[self rearrangeView];
return YES;
}
这里txtActiveField是UItextField类型的实例变量发布一些代码。您是如何做到的。请尝试TPKeyboardAvoidingScrollView。。。这将处理所有事情。:)