1

I have added scrollView top,left,right,bottom 0. in scrollView i have added viewinScrollview with height 550, in this view i have added fieldsContainerView. like below

storyboard view hierarchy img

if i run project in iPhone8 then design looks good, but if i run in iPhone 11 pro i am seeing unnecessary scrollview. i have given scrollview color is green and viewinScrollview color is white.

in iPhone 11 pro i am getting like below, the green space is scroll view i dont want that space after keyboard iPhone 11 pro

this is iPhone8 simulator iPhone8 i need like this in all iPhone sizes.

here is the code:

 override func viewDidLoad() {
      super.viewDidLoad()

      NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
      NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidHide), name: UIResponder.keyboardDidHideNotification, object: nil)

  }

  @objc func keyboardDidShow(notification: NSNotification) {
      let info = notification.userInfo
      let keyBoardSize = info![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect
      scrolView.contentInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyBoardSize.height, right: 0.0)
      scrolView.scrollIndicatorInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyBoardSize.height, right: 0.0)
  }

  @objc func keyboardDidHide(notification: NSNotification) {
      scrolView.contentInset = UIEdgeInsets.zero
      scrolView.scrollIndicatorInsets = UIEdgeInsets.zero
  }

please help me to remove green color space in all iPhone sizes.

Llex
  • 1,770
  • 1
  • 12
  • 27
Swift
  • 1,074
  • 12
  • 46

3 Answers3

0

Here is the Library which helps you to manage the Textfields inside the scrollView, TableView, CollectionView. You can use this library. With the help of this library you don't need to manage the scrollview content inset for every device.

Github Link:- https://github.com/hackiftekhar/IQKeyboardManager

Mandeep Singh
  • 2,810
  • 1
  • 19
  • 31
0

Remove background colour of scrollview in your storyboard .

You can follow my approach for more clarifications .

moving-keyboard-when-editing-multiple-textfields-with-constraints-swift

Vasucd
  • 357
  • 2
  • 10
  • Okay, like this only i want, but in third textfield why its moving up again, there no need to move in iphoneXR right – Swift Dec 17 '19 at 05:40
  • bro you didn't answer my comment?? i have added pod 'TPKeyboardAvoiding' in my project but it is not working? why? whats wrong?, why u did not import TPKeyboardAvoiding – Swift Dec 18 '19 at 10:30
  • Hi @iPhoneDev you did not need to import 'TPKeyboardAvoiding' . In your storyboard , set scrollview class name to 'TPKeyboardAvoidingScrollview' in UIViewcontroller . it will work . Use this link for more details https://stackoverflow.com/questions/1126726/how-can-i-make-a-uitextfield-move-up-when-the-keyboard-is-present-on-starting/59317509#59317509 – Vasucd Dec 18 '19 at 10:40
  • it works i have accepted ur answer, but in your project keyboard u have next for all textfields in last textfield u r getting done.. how ?? i am getting only return button – Swift Dec 18 '19 at 11:01
  • In the inspector tab of each textfields , leave return key to default . That's what I've done in my project . – Vasucd Dec 18 '19 at 11:08
0

Use the following Library which helps to manage the textField or textView inside any contentView

Github Link:- https://github.com/Sunilkumar01091985/KeyBoard/tree/master

sunilkumar
  • 179
  • 1
  • 2
  • 10