我在UITextField
中有5个UIScrollView
,当我触摸第四个文本字段时,键盘出现,但它出现在文本字段上方(文本字段仍在键盘下方),我看不到我在键入什么。
我尝试使用-scrollRectToVisible:CGRectMake
更改了contentSize
的大小,并且工作正常。
但是这种行为是无法理解的。谁能告诉我此功能的实际工作原理?
最佳答案
试试看
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
CGRect rc = [textField bounds];
rc = [textField convertRect:rc toView:self.scrollView];
CGPoint pt = rc.origin;
pt.x = 0;
if(rc.origin.y > 200) // here you can also change value 200 and 150 as per your requirement.
pt.y -= 150;
else
pt.y -= rc.origin.y;
[self.scrollView setContentOffset:pt animated:YES];
return YES;
}
关于ios - scrollRectToVisible:CGRectMake无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552341/