简体   繁体   English

UIStackView 内的 UIScrollView 具有动态变化的项目

[英]UIStackView inside UIScrollView with dynamically changing items

I'm trying to have a UIStackView in a UIScrollView with changing content in the UIStackView as shown below in the image.我想有一个UIStackViewUIScrollView不断变化的内容UIStackView为图像中显示如下。 How ever I don't manage to get it to work properly.我怎么没能让它正常工作。 When I launch my app it does not scroll and only 10 items are shown in the stack view, not the 20 I expected.当我启动我的应用程序时,它不会滚动,堆栈视图中只显示 10 个项目,而不是我预期的 20 个。 Also it does not scroll all the way down of the UIStackView .此外,它不会一直向下滚动到UIStackView

Note it's important that this can work on both iPhone and iPad even when rotated.请注意,即使在旋转时,这也可以在 iPhone 和 iPad 上运行,这一点很重要。

场景

I have the following code in my View Controller (that's all):我的视图控制器中有以下代码(仅此而已):

@IBOutlet weak var stackView: UIStackView!

override func viewDidLoad() {
    super.viewDidLoad()

    for i in 1 ... 20 {
        let vw = UILabel()
        vw.text = "Holiday #\(i)"
        stackView.addArrangedSubview(vw);
    }
}

I found a solution using this as a foundation: https://github.com/oliverfoggin/AnimalBrowser我找到了一个以此为基础的解决方案: https : //github.com/oliverfoggin/AnimalBrowser

The code remains the same, but I changed around a bit on the scene and now it works!代码保持不变,但我在现场稍微改变了一点,现在它可以工作了!

场景

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM