gpt4 book ai didi

ios - UIScrollView不显示动态添加的内容

转载 作者:行者123 更新时间:2023-11-30 13:32:28 26 4
gpt4 key购买 nike

我需要一些有关 UIScrollView 的帮助。我正在加载内容:

for i in _start ..< _loopPages {

let articleController = createViewController(index: i)
viewControllers.append(articleController)
articleController.didMoveToParentViewController(self)
scrollView.addSubview(articleController.view)
articleController.view.setNeedsDisplay()
}

这是计算 View 大小的函数:

func calculateScrollViewSize(){
for i in _start ..< numberOfArticles {
let articleController = viewControllers[i]
articleController.view.frame = view.bounds
let x = i * Int(articleController.view.bounds.size.width)
print("RECT: ", CGRect(origin: CGPoint(x: x, y: 0), size: view.bounds.size))
articleController.view.frame = CGRect(origin: CGPoint(x: x, y: 0), size: view.bounds.size)
}

let contentWidth = CGFloat(numberOfArticles) * view.bounds.size.width
let contentHeight = view.bounds.size.height
scrollView.contentSize = CGSize(width: contentWidth, height: contentHeight)

let offsetX = currentPage * Int(view.bounds.size.width)
let offsetY = 0
scrollView.contentOffset = CGPoint(x: offsetX, y: offsetY)
//scrollView.contentInset.top = 0

scrollView.setNeedsDisplay()
}

前 10 个 View 已按预期加载和显示,但当我加载接下来的 10 个 View 时,我得到的只是空白。如果我更改屏幕方向,则会显示页面,但如果我不更改,我得到的只是白屏。我可以滚动屏幕, ScrollView 的大小已更新,但内容未显示。当用户滚动到第 10 页时,将加载接下来的 10 页。你们中的任何人都可以告诉我我在这里做错了什么吗?

最佳答案

我的问题是动态添加的 View 的大小为零,因此在我将 viewController (在 createViewController(index: i) 方法中创建的 View Controller )的大小设置为屏幕的大小后,一切都像这样魅力。

希望有一天它能帮助别人。

关于ios - UIScrollView不显示动态添加的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36410890/

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