【问题标题】:Smoother Auto-Scrolling in UITableViewUITableView 中更平滑的自动滚动
【发布时间】:2016-06-11 11:54:36
【问题描述】:

我有一个拖放开关语句,它允许用户抓取一个单元格,代码无缝创建它的快照,然后用户可以将快照拖动到新位置。繁荣!细胞移动。

当行/单元格的数量比 iPhone 的屏幕长时,我添加了代码以允许用户向上/向下拖动表格。

if locationOnScreen.y < 200 && indexPath!.row > 1 {
    let indexPath = NSIndexPath(forRow: indexPath!.row-1, inSection: 0)
    tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Top, animated: false)
} else if locationOnScreen.y > 550 && indexPath!.row < listCount {
    let indexPath = NSIndexPath(forRow: indexPath!.row+1, inSection: 0)
    tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: false)
}

注意:单元格的高度各不相同,有些占据屏幕高度的一半,有些则小得多。

问题

此代码有效,但它可以快速向上/向下对齐表格。它非常适合快速到达表格的顶部或底部,但不适合逐渐滚动。有什么想法吗?

有没有办法,如果拖动的单元格靠近顶部,表格以每秒固定的速率向上滚动?如果接近底部,是否会以每秒固定的速率向下滚动?

【问题讨论】:

  • 你可以试试 animateWithDuration 来减慢速度,效果很慢。

标签: ios swift uitableview scroll drag-and-drop


【解决方案1】:

尝试传递animated: true。它应该滚动到带有动画的单元格

if locationOnScreen.y < 200 && indexPath!.row > 1 {
    let indexPath = NSIndexPath(forRow: indexPath!.row-1, inSection: 0)
    tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Top, animated: true)
} else if locationOnScreen.y > 550 && indexPath!.row < listCount {
    let indexPath = NSIndexPath(forRow: indexPath!.row+1, inSection: 0)
    tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: true)
}

【讨论】:

  • 这仍然是生涩的。这可能是因为单元格的高度不同,有些占据屏幕高度的一半,有些则小得多。有没有办法,如果拖动的单元格靠近顶部,则表格以每秒固定的速率向上滚动?如果接近底部,是否会以每秒固定的速率向下滚动?
  • 戴夫你知道了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-12
  • 1970-01-01
  • 2020-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多