【问题标题】:UIScrollView starts out halfway down content [duplicate]UIScrollView 从内容的中途开始[重复]
【发布时间】:2017-03-19 17:27:30
【问题描述】:

我正在尝试以与 App Store 顶部的特色横幅类似的方式实现 UIScrollView。我正在添加 3 个视图,然后使用下面的代码对它们进行分页。然而,当控制器加载时,它会以内容稍微下降的方式启动。如果我点击视图,内容会回到它应该在的位置。我怎样才能解决这个问题?我尝试将内容偏移设置为 0,我尝试手动滚动到原始矩形,我尝试将我的视图放在内容视图中,但没有任何效果。

    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)
    }

【问题讨论】:

  • 成功了!回复答案,我会将其标记为正确。谢谢!
  • 这不是问题,但在这种情况下 UICollectionView 比 UIScrollView 更好

标签: ios uiscrollview


【解决方案1】:

您是否尝试将automaticallyAdjustsScrollViewInsets 设置为NO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 2011-05-13
    • 2020-08-18
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多