Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make a UITextField move up when the keyboard is present?
    primarykey
    data
    text
    <p>With the iOS SDK:</p> <p>I have a <code>UIView</code> with <code>UITextField</code>s that bring up a keyboard. I need it to be able to:</p> <ol> <li><p>Allow scrolling of the contents of the <code>UIScrollView</code> to see the other text fields once the keyboard is brought up</p></li> <li><p>Automatically "jump" (by scrolling up) or shortening</p></li> </ol> <p>I know that I need a <code>UIScrollView</code>. I've tried changing the class of my <code>UIView</code> to a <code>UIScrollView</code> but I'm still unable to scroll the textboxes up or down. </p> <p>Do I need both a <code>UIView</code> and a <code>UIScrollView</code>? Does one go inside the other?</p> <p>What needs to be implemented in order to automatically scroll to the active text field?</p> <p>Ideally as much of the setup of the components as possible will be done in Interface Builder. I'd like to only write code for what needs it.</p> <p>Note: the <code>UIView</code> (or <code>UIScrollView</code>) that I'm working with is brought up by a tabbar (<code>UITabBar</code>), which needs to function as normal.</p> <hr> <p>Edit: I am adding the scroll bar just for when the keyboard comes up. Even though it's not needed, I feel like it provides a better interface because then the user can scroll and change textboxes, for example. </p> <p>I've got it working where I change the frame size of the <code>UIScrollView</code> when the keyboard goes up and down. I'm simply using: </p> <pre><code>-(void)textFieldDidBeginEditing:(UITextField *)textField { //Keyboard becomes visible scrollView.frame = CGRectMake(scrollView.frame.origin.x, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height - 215 + 50); //resize } -(void)textFieldDidEndEditing:(UITextField *)textField { //keyboard will hide scrollView.frame = CGRectMake(scrollView.frame.origin.x, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height + 215 - 50); //resize } </code></pre> <p>However, this doesn't automatically "move up" or center the lower text fields in the visible area, which is what I would really like.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload