2016-11-06 56 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