IOS - Prevent keyboard from hiding Text Field? [duplicate]

1

When I click on Text Field, the keyboard pops up hiding it on the screen, I would like to know a way to make Text Field go up along with the keyboard, I tried to use a Scroll View but I could not.

Example:

    
asked by anonymous 18.02.2016 / 19:02

2 answers

1

Create the delegate for the textfields and IBOutlet for the scroll and use the following code:

SWIFT:

  func textFieldDidBeginEditing(textField : UITextField)
  {
      var pt : CGPoint
      var rc = textField.bounds
      rc = textField.convertRect(rc, toView: self.scroll)
      pt = rc.origin;
      pt.x = 0;
      pt.y -= 157;  // Ajuste de acordo com a necessidade
      self.scroll.setContentOffset(pt, animated: true)
  }

OBJECTIVE-C

- (void)textViewDidBeginEditing:(UITextField *)textField
{
    CGPoint pt;
    CGRect rc = [textField bounds];
    rc = [textField convertRect:rc toView:self.scroll];
    pt = rc.origin;
    pt.x = 0;
    pt.y -= 157;  // Ajuste de acordo com a necessidade
    [self.scroll setContentOffset:pt animated:YES];    
}
    
18.02.2016 / 19:46
1

You can use the TPKeyboardAvoiding lib ( link ).

Just change the class from UIScrollView to TPKeyboardAvoidingScrollView .

    
18.02.2016 / 22:38