【发布时间】:2016-04-04 19:08:35
【问题描述】:
我需要一些有关 UIScrollView 的帮助。我正在加载内容:
for i in _start ..< _loopPages {
let articleController = createViewController(index: i)
viewControllers.append(articleController)
articleController.didMoveToParentViewController(self)
scrollView.addSubview(articleController.view)
articleController.view.setNeedsDisplay()
}
这是计算视图大小的函数:
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 个视图按应有的方式加载和显示,但是当我加载接下来的 10 个视图时,我得到的只是空白。如果我更改屏幕方向,则会显示页面,但如果我不这样做,我得到的只是白屏。我可以滚动屏幕,滚动视图的大小已更新,但内容不显示。当用户滚动到第 10 页时,正在加载下一个 10。你们谁能告诉我我在这里做错了什么。
【问题讨论】:
标签: ios iphone swift uiscrollview