gpt4 book ai didi

ios - UIScrollView 底部的 UIButton 不起作用

转载 作者:可可西里 更新时间:2023-11-01 02:12:26 25 4
gpt4 key购买 nike

我的 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
}

...我注意到只有在 View 顶部添加一个 UIButton 时它才会起作用 - 我只能通过滚动到达的那些(例如底部的那个)不会。

好吧,我想,所以按钮是在容器 View 框架之外创建的,因此我将以下行添加到我的updateScrollViewSize 方法中。

containerView.frame.size = contentRect.size

遗憾的是,这并没有解决我的问题。

我已经尝试了很长一段时间来寻找解决方案,但没有人能帮助我。我仍然 99% 确定它与我的 Container Views 框架有关,但我就是想不出如何解决这个问题。任何帮助将不胜感激!

最佳答案

如果使用任何约束,请在创建 subview 后在顶 View 上调用 layoutIfNeeded()。确保 scrollView 的 contentSize 与您的 containerView.frame 匹配(不是 .bounds,因为这不会告诉您例如您的框架 y 位置低于零。

关于ios - UIScrollView 底部的 UIButton 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40612254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com