Scroll Uiscrollview automatically when entering Uitextfield

Asked

Viewed 102 times

1

I need to create a form that scrolls the screen as it is filled out. The idea is that the screen scrolls as I fill and so displaying the fields that are below the keyboard.

  • Alex, put Ios in the tags. Do you have another language? Javascript maybe? And have you tested any code? Post at least your HTML for the question to be perceptible. And welcome to Stackoverflow!

  • Language used? Swift? Objective-C? HTML?

2 answers

2

It’s pretty easy, Alex. What you need is to check when the particular textfield will start editing, and then set contentOffset to your scrollView. As in the example below:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{


    if ([textField isEqual:self.myTextField]) {

        [self.myScrollView setContentOffset:CGPointMake(0, 240) animated:YES];
    }

    return YES;

}

Remember to set the delegate of the Uitextfield before. You can do this by storyboard or during viewDidLoad. Also remember to always return YES, otherwise the keyboard does not go up. Good Luck!

0


I usually use a tableViewController with Static Cells. When the next one becomes firstResponder and it is below the keyboard, the tableView goes up automatically.

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if ([textField isEqual:self.seuTextField]) {

        [self.proximoTextField becomeFirstResponder];

    }

    return YES;
}

When the user touches the Return button on his keyboard, the next textField becomes the firstResponder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.