0

I have this code that can push everything up in my view controller when the keyboard displays. However, it doesn't work with auto layout. Can I adapt this code to work with my constraints or is there a better method to move textfields and buttons up so that the keyboard doesn't hide them? Thanks.

    func keyboardWillShow(sender: NSNotification) {
    self.view.frame.origin.y -= 150
}
func keyboardWillHide(sender: NSNotification) {
    self.view.frame.origin.y += 150
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • Take a look at this answer: http://stackoverflow.com/questions/25693130/move-textfield-when-keyboard-appears-swift – Amir Dec 31 '14 at 20:49
  • i looked at that but I am confused with the bottom space to superview constraint. Do i set that for every textfield and button I have? Do I just set it for the bottommost element? – Jeff Mathers Dec 31 '14 at 20:56
  • please see this extension http://stackoverflow.com/a/36808722/3472073 it should help you – ale_stro Apr 23 '16 at 09:03

0 Answers0