IOS - Prevent the keyboard from hiding Text Field?

Asked

Viewed 230 times

1

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

Example:

inserir a descrição da imagem aqui

  • 1

    Take a look in this answer, has a library tip that solves this your question.

  • Thank you Paulo, I will try here and I warn if you have succeeded!

2 answers

1


Create delegate for textfields and Iboutlet for 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];    
}
  • Thanks Ccastro, I’ll try now in the morning and anything I warn you here.

  • I got it here :D I just had to put the scope of the code inside -(Ibaction)textField:(id)Sender{} Hug!

1

  • When I added the framework and changed the scroll class to Tpkeyboardavoiding it stopped working. Now in the morning I’ll create a new project, just to test it again

Browser other questions tagged

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