2016-11-06 57 views
0

我想實現一個UIScrollView以類似的方式在App Store頂部的特色橫幅。我添加3個視圖,然後使用下面的代碼對它們進行分頁。然而,當控制器加載時,它會隨着內容的下降而啓動。如果我點擊視圖,內容會回到它應該在的位置。我怎樣才能解決這個問題?我試圖設置內容偏移量爲0,我試過手動滾動到原始矩形,並試圖將我的視圖放在內容視圖中,但沒有任何工作。UIScrollView開始一半的內容

featuredScrollView.alwaysBounceVertical = false 
    featuredScrollView.contentSize = CGSize(width: 3 * featuredScrollView.frame.size.width, height: featuredScrollView.frame.size.height) 
    let contentView = UIView(frame: CGRect(x: 0, y: 0, width: 3 * featuredScrollView.frame.size.width, height: featuredScrollView.frame.size.height)) 
    featuredScrollView.addSubview(contentView) 
    for i in 0..<3 
    { 
     let testView = UIView(frame: CGRect(x: CGFloat(i) * featuredScrollView.bounds.size.width, y: 0, width: featuredScrollView.bounds.size.width, height: featuredScrollView.bounds.size.height)) 
     testView.backgroundColor = .blue 
     testView.layer.borderColor = UIColor.white.cgColor 
     testView.layer.borderWidth = 1 
     contentView.addSubview(testView) 
    } 

+0

這樣做的竅門!回答答案,我會將其標記爲正確。謝謝! –

+0

這不是關於問題,但在這種情況下,UICollectionView更好,只是UIScrollView –

回答

1

你嘗試設置automaticallyAdjustsScrollViewInsetsNO