2016-04-04 13 views
0

私はUIScrollViewに関するいくつかの助けが必要です。私はロードするときUIScrollViewは動的に追加されたコンテンツを表示しません

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個のビューがロードされ、彼らが必要として表示されますが、:

for i in _start ..< _loopPages { 

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

を、これはビューのサイズを計算する関数である:私はこれでコンテンツをロードしています私が得る次の10のビューは空白です。私が画面の向きを変えるとページが表示されますが、もし私がそうでなければ白い画面が表示されます。画面をスクロールできますが、スクロールビューのサイズは更新されますが、コンテンツは表示されません。ユーザーがページ10にスクロールすると、次の10がロードされます。ここで間違っていることを教えていただけますか?

答えて

0

私の問題は、動的に追加されたビューのサイズがゼロだったので、viewController(createViewController(index:i)メソッドで作成されたもの)のサイズを画面のサイズに設定した後、魔法のように。

いつか誰かに役立つことを願っています。