Roll UIscrollView automatically when entering UItextField

1

I need to create a form that will make the screen scroll as it fills in. The idea is that the screen roll as I fill it out and thus displaying the fields below the keyboard.

    
asked by anonymous 14.11.2014 / 09:50

2 answers

0

I often 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 their keyboard, the next textField becomes the firstResponder.

    
25.11.2014 / 11:33
2

It's very easy Alex. What you need is to check when the given textfield starts to be edited, and then set the contentOffset of 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 UITextField delegate before. You can do this through storyBoard or during viewDidLoad. Also remember to always return YES, otherwise the keyboard will not go up. Good Luck!

    
19.11.2014 / 12:57