UITableView中的平滑器自动滚动

问题描述:

我有一个允许用户抓取单元的拖放切换语句,代码可以无缝地创建它的快照,然后用户可以将快照拖动到新的位置。繁荣!细胞移动。UITableView中的平滑器自动滚动

对于行数/单元格数量比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) 
} 

注:细胞变化的高度,一些占据屏幕高度的一半,其他的要小得多。

问题

此代码的工作,但迅速回落卡表上/。快速到达桌面的顶部或底部非常好,但不适合逐渐滚动。有任何想法吗?

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

+0

您可以尝试animateWithDuration减慢速度,效果较慢。 –

尝试通过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) 
} 
+0

这仍然是生涩的。这可能是因为细胞高度不同,有的占据屏幕高度的一半,有的则小得多。有没有办法让拖动的单元格靠近顶部,表格以每秒固定的速率向上滚动?如果靠近底部,将以每秒固定速率向下滚动? –

+0

你觉得戴夫? –