Мне нужна помощь с UIScrollView. Я загрузка содержимого в этом: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 просмотров, которые я получаю, - это пробел. Если я изменяю ориентацию экрана, страницы отображаются, но если я не все, что получаю, это белые экраны. Я могу прокручивать экраны, размер scrollview обновляется, но содержимое не отображается. Когда пользователь прокручивает страницу до 10, загружаются следующие 10. Может ли кто-нибудь из вас сказать мне, что я делаю неправильно здесь.