0

There is a segmented control, each with different heights. There is also some textfields in each of them. when I tap on the textfield then tap on another segment, I cannot scroll to the bottom of view while the keyboard is shown.
I wanted to fix this with these codes which didn't work.

if(self.isKeyBoardShowing) {
    CGRect borderLabelRect = containerView.frame;
    self.scrollView.contentSize = CGSizeMake(borderLabelRect.size.width , borderLabelRect.size.height + 325);
    [self.view layoutIfNeeded];
    [self.view layoutSubviews];
}
Fattaneh Talebi
  • 753
  • 13
  • 34

2 Answers2

2

Add an observer in viewDidLoad

NotificationCenter.default.addObserver(self, selector: #selector(onShowKeyboard), name: NSNotification.Name.UIKeyboardWillShow, object: nil)

and implement selector as ->

 @objc func onShowKeyboard(_ notification:Notification) {

    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
    }
}
0

Remove your code you have done for keyboard setting.

Just paste IQKeyboard manager in your project ,it will scroll automatically.

Download from below link

https://github.com/hackiftekhar/IQKeyboardManager

Eric Aya
  • 68,765
  • 33
  • 165
  • 232
Sagar koyani
  • 327
  • 1
  • 10