1290 1290 - 6 months ago 12
iOS Question

Scrollview not changing content size

I have two textfields which I embedded in into a scrollview using:

Editor -> Embed In -> Scroll View
from XCode. But now when I try to change the contentSize of the scrollview in viewDidLoad:

override func viewDidLoad() {
emailTextField.delegate = self
passwordTextField.delegate = self

scrollView.contentSize = CGSizeMake(500, 1000)

The above code doesn't change the height of the scrollview no matter what value I put:
1000, 2000, etc.
just to see if it is working. Is there something wrong I am doing?


Consider observing the system notifications:

  • UIKeyboardWillShowNotification
  • UIKeyboardDidShowNotification
  • UIKeyboardWillHideNotification
  • UIKeyboardDidHideNotification

And check the documentation

You should move the view that wraps all the UITextFields (if no such view, just create a "form view" containing those fields). The userInfo property of the notification object contains the size of the keyboard. You can use that information and position the form view with a distance from the keyboard frame.