【发布时间】:2017-03-29 11:28:23
【问题描述】:
我的 UI 结构是这样的:
- View
- Scroll View
- Container View
- Dynamically added UI element
- Dynamically added UI element
- Dynamically added UI element
- ....
- UIButton
添加所有 UI 元素(包括带有 UITapGestureRecognizer 的 UIButton)并使用以下方法更新 UIScrollView 大小后...
func updateScrollViewSize() {
var contentRect = CGRect.zero
for view in containerView.subviews {
contentRect = contentRect.union(view.frame)
}
contentRect.size = CGSize(width: scrollView.contentSize.width, height: contentRect.height + TRAILING_SCROLLVIEW_SPACE)
scrollView.contentSize = contentRect.size
}
...我注意到只有在视图顶部添加一个 UIButton 时它才会起作用 - 我只能通过滚动到达的那些(例如底部的那个)不起作用。
好吧,我想,所以按钮是在容器视图的框架之外创建的,因此我在updateScrollViewSize 方法中添加了以下行。
containerView.frame.size = contentRect.size
很遗憾,这并没有解决我的问题。
我尝试寻找解决方案已经有一段时间了,但没有人能帮到我。我仍然 99% 确定它与我的 Container Views 的框架有关,但我根本不知道如何解决这个问题。任何帮助将不胜感激!
【问题讨论】:
-
尝试将容器视图的 -clipsBounds 设置为 true/yes。按钮是否仍然可见?
-
set contentSize of scrollView height = 最后添加 ui 组件的 y pos + height + 10 或相应的。
-
@isaac:不是。我使用
print containerView.frame.bounds对其进行了调试,并且高度根据内容发生了相应的变化。这是我访问的错误属性吗?
标签: ios swift uiscrollview uibutton