为什么滚动时我的UIView在UIScrollView中移动了?(Why is my UIView moving out of place inside UIScrollView when scrol

编程入门 行业动态 更新时间:2024-10-27 06:25:52
为什么滚动时我的UIView在UIScrollView中移动了?(Why is my UIView moving out of place inside UIScrollView when scrolled?)

所以我在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

更多推荐

本文发布于:2023-07-16 15:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中移动   UIScrollView   UIView   scrolled   place

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!