I have 5 UITextField
s in a UIScrollView
and when I touch the 4th textfield the keyboard appears, but it appears over the textfield (the textfield remains below the keyboard) and I can not see what I am typing.
I tried to use -scrollRectToVisible:CGRectMake
shifted the contentSize
size, and it is working fine.
But the behaviour is not understandable. Can anyone tell me how this function actually works?
Try with
- (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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.