0

So I made a test project in Xcode to see how I can use a UITextField and UILabels, which are subviews of a UIView. And the UIView is a subview of a UIScrollView. So after adding the views and the code in viewDidAppear and when I scroll down the UIView moves out of place.

Here is a video of the problem: https://drive.google.com/file/d/0B5j_BdtRjSyARWp3cGQ1dkMzMFk/view?usp=sharing

Please tell me what I am doing wrong.

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    scrollView.contentSize.height = 1000

    scrollView.contentSize.width = view.frame.width

    scrollView.showsHorizontalScrollIndicator = false
    scrollView.showsVerticalScrollIndicator = false

    scrollView.contentOffset.x = -8

    scrollView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.25)
    scrollViewChildView.backgroundColor = UIColor.blueColor().colorWithAlphaComponent(0.25)
}

enter image description here

enter image description here

jsondwyer
  • 437
  • 8
  • 18
RoboChris
  • 387
  • 1
  • 5
  • 18

1 Answers1

1

You try to layout your views after it were positioned with autolayout system, so after you force it to layoutSubviews (with dragging to bottom) your content moves as presumed with specified offset that you are set to it (x = -8 and y = 0). For more information, referred to this question

Community
  • 1
  • 1
Igor Kislyuk
  • 330
  • 1
  • 4
  • 14