【问题标题】:How to change UIScrollView with isPagingEnabled autoscroll drag trashhold如何使用 isPagingEnabled 自动滚动拖动垃圾桶更改 UIScrollView
【发布时间】:2020-04-25 21:39:16
【问题描述】:

我有水平的 UIScrollViewisPagingEnabled = true 包含几页。如果我拖动滚动视图内容并释放手指,只有当我拖动至少 50% 的滚动视图宽度时,它才会滚动到下一页。如果拖动距离超过 25%,我想自动滚动到下一页/上一页。

我能够通过在UIScrollViewDelegate 中覆盖scrollViewDidEndDragging、计算拖动距离并调用scrollView.setContentOffset 来实现它。但问题是,如果距离 > 25 且

知道如何实现这一目标吗?谢谢

【问题讨论】:

    标签: ios swift uiscrollview uiscrollviewdelegate


    【解决方案1】:

    我将通过修改所需页面的偏移量来使用以下委托的回调

    // called on finger up if the user dragged. velocity is in points/millisecond. 
    // targetContentOffset may be changed to adjust where the scroll view comes to rest
    @available(iOS 5.0, *)
    optional func scrollViewWillEndDragging(_ scrollView: UIScrollView, 
        withVelocity velocity: CGPoint, 
        targetContentOffset: UnsafeMutablePointer<CGPoint>)
    

    【讨论】:

    • 它不起作用。我不想要不同的 targetContentOffset。我想将页面动画到相同的位置。
    • 让我们对齐...如果页面宽度等于 100,那么如果在第一页上拖动 26%,那么 targetContentOffset 将为 26 并且 scrollView 将其返回为 0,但如果在此将 targetContentOffset 设置为 100 的情况下,它会向前滚动到第二页。这不是预期的吗?
    猜你喜欢
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    相关资源
    最近更新 更多