I have a uiscrollview in one of my VC. Inside scrollView, I have some TF buttons, buttons, etc. I am using the Apple documentation code below to move the scroll upward when a keyboard notification is called to push hidden text fields. However, when I close the keyboard, scrollView does not reset or move backward, it just remains in the "moved up" position.
Am I missing something? I have a class member variable:
var activeTextField: UITextField!
Am I using this correctly using delegate methods?
(func registerForKeyboardNotifications() { let notificationCenter = NSNotificationCenter.defaultCenter() notificationCenter.addObserver(self, selector: "keyboardWillBeShown:", name: UIKeyboardWillShowNotification, object: nil) notificationCenter.addObserver(self, selector: "keyboardWillBeHidden:", name: UIKeyboardWillHideNotification, object: nil) } func keyboardWillBeShown(sender: NSNotification) { let info: NSDictionary = sender.userInfo! let value: NSValue = info.valueForKey(UIKeyboardFrameBeginUserInfoKey) as NSValue let keyboardSize: CGSize = value.CGRectValue().size let contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0) scrollView.contentInset = contentInsets scrollView.scrollIndicatorInsets = contentInsets
source share