0

I'm using some functions to move the UITextFieldsimmediately after InputView, see my code below:

func DismissKeyboard(){
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    view.endEditing(true)
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.registerForKeyboardNotifications()
}

override func viewDidDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    NSNotificationCenter.defaultCenter().removeObserver(self)
}

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 + 8, 0.0)
    backgroundScrollView.contentInset = contentInsets
    backgroundScrollView.scrollIndicatorInsets = contentInsets
}

// Called when the UIKeyboardWillHideNotification is sent
func keyboardWillBeHidden(sender: NSNotification) {
    let insets: UIEdgeInsets = UIEdgeInsetsMake(self.backgroundScrollView.contentInset.top, 0, 0, 0)

    //let insets: UIEdgeInsets = UIEdgeInsetsZero
    backgroundScrollView.contentInset = insets
    backgroundScrollView.scrollIndicatorInsets = insets

}
func textFieldShouldReturn(textField: UITextField) -> Bool {
    textField.resignFirstResponder()
    return true
}

What is happening is, after tap on the first UITextField, backgroundScrollView stop scroll, and my app there are lot of fields that need to scroll screen to see.

What may I doing wrong?

  • can u check the `contentsize` of `backgroundScrollView` inside the `keyboardWillBeShown` and `keyboardWillBeHidden` function.. if it is less than display area size or 0 – Venk Dec 02 '15 at 12:41
  • How can I check this? I'm very new on this. – Felipe Boechat Dec 02 '15 at 12:48

1 Answers1

0

In keyboardWillBeShown() method setcontentSize: -

backgroundScrollView.contentSize = CGSizeMake(0, 600)

0 "width" means -> Dont scroll in x direction

600 "height" means -> Scroll content can be scroll upto 600 height

Bhuvan Bhatt
  • 3,276
  • 2
  • 18
  • 23