所以我在Xcode中做了一个测试项目,看看我如何使用UITextField和UILabel ,它们是UIView子视图。 UIView是UIScrollView的子视图。 因此,在viewDidAppear添加视图和代码之后,当我向下滚动时, UIView移动到位。
以下是该问题的视频: https : //drive.google.com/file/d/0B5j_BdtRjSyARWp3cGQ1dkMzMFk/view?usp=sharing
请告诉我我做错了什么。
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) }
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) }最满意答案
您尝试在使用自动布局系统定位视图后对其进行布局,因此在将其强制转换为layoutSubviews (拖动到底部)后,您的内容会按照设置的指定偏移量进行设置(x = -8和y = 0) )。 有关更多信息,请参阅此问题
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
更多推荐
发布评论