【问题标题】:How to auto scrolling of collectionView?如何自动滚动collectionView?
【发布时间】:2017-03-01 00:37:32
【问题描述】:

当我使用长按手势拖动UICollectionView 的部分和移动时,如何自动滚动UICollectionView's 滚动视图。

注意:UICollectionView 第 0 和第 1 部分不向下滚动,仅向前部分滚动。 0 和 1 部分设置为粘性,当我移动部分时不会滚动。

【问题讨论】:

  • 你的问题现在让我有点困惑。如果我理解正确。您希望 collectionViewCell 在每次触摸时移动到中心,向左或向右是您想要的,或者您希望集合在加载到视图时滚动...您需要不同的方法来实现这一点。让我来know.personally 我在我的项目中使用上面的代码。我从来没有遇到过代码问题。请告诉我..
  • 那么您将无法获得答案。只需制作一个简单的测试项目来模拟您的问题并上传该代码。您必须给我们一些东西,以便我们回报您的青睐...祝你好运

标签: ios swift scroll uicollectionview


【解决方案1】:

未经测试的代码:

在您的 viewDidload 或 viewWillAppear 中尝试此代码。

   let indexPath = NSIndexPath(forRow: 10, inSection: 0) // 1
    self.collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: UICollectionViewScrollPosition.Left, animated: true)

【讨论】:

  • 我已经实现了这段代码,但它没有像我问的那样工作
  • 使用 scrollToItemAtIndexPath 还可以滚动第 0 节和第 1 节
  • 抱歉我不能分享
【解决方案2】:

解决了。

 func handleLongGesture(gesture: UILongPressGestureRecognizer) { //dragging Functionality handled here.
    let point = gesture.locationInView(self.collectionView)
    switch(gesture.state) {

        case UIGestureRecognizerState.Changed:
        let gesturePoint = gesture.locationInView(self.collectionView)
        guard let changeIndexPath = self.collectionView.indexPathForItemAtPoint(gesturePoint)
            where changeIndexPath.section > 1 else {
            break
        }
     }
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 2021-01-25
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多