Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检测UITableViewCell何时将离开UITableView_Ios_Swift_Uitableview - Fatal编程技术网

Ios 检测UITableViewCell何时将离开UITableView

Ios 检测UITableViewCell何时将离开UITableView,ios,swift,uitableview,Ios,Swift,Uitableview,每当一个UITableViewCell即将离开视图时,我都要为它设置动画。我知道有一个didendisplayingcell函数,但是到那时,为单元格设置动画已经太晚了。因为它不见了。我基本上想用…缩小单元格的大小 UIView.animate(withDuration: 0.2) { self.cellView.transform = CGAffineTransform(translationX: self.view.frame.size.width, y: 0) } …每当它出现在

每当一个
UITableViewCell
即将离开视图时,我都要为它设置动画。我知道有一个
didendisplayingcell
函数,但是到那时,为单元格设置动画已经太晚了。因为它不见了。我基本上想用…缩小单元格的大小

UIView.animate(withDuration: 0.2) {
    self.cellView.transform = CGAffineTransform(translationX: self.view.frame.size.width, y: 0)
}
…每当它出现在屏幕上时,将其缩放回正常值


有什么想法吗?

不是一个完整的解决方案,但这可能会让你达到目的:

self.tableView.indexPathsForVisibleRows
使用此选项可以查找屏幕上的内容

for path in self.tableView.indexPathsForVisibleRows! {
    //check if it's past a point on the screen
    //animate if needed
}
在中检查这些条件

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    // call the function to check if cells pass a threshold
}

最后一位将对其进行设置,以使单元格在第一次加载时完全可见,但在加载之后,它们将以要设置动画的状态启动。

最好的方法是通过
UITableViewDelegate
方法检查单元格何时完成显示:

func tableView(UITableView, didEndDisplaying: UITableViewCell, forRowAt: IndexPath)
通知委托指定的单元格已从表中删除


我无法测试正确的解决方案,但由于表视图基本上基于滚动视图,因此您应该能够使用滚动视图的内容偏移量,并将其与表本身的高度以及单元格本身的位置进行比较。从这3个值中,您应该能够知道单元格将在何时显示或隐藏。使用自定义CollectionViewFlowLayout和
UICollectionView
可以很容易地实现类似的功能。