Preface
This article carries strong personal sentiment. If it makes you uncomfortable, please close it as soon as possible. This article is only for personal study records. Reprinting or sharing within the scope of the license is also welcome. Please respect the copyright and keep the original link. Thank you for your understanding and cooperation. If you find this site helpful, you can subscribe via RSS. Thanks for your support!
How to detect that a cell has scrolled off screen?
1
2
3
4
5
6
7
8
9
10
11
12
13
//Determine whether the cell view is on screen. If not, stop playback
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (_currentPlayIndexPath) {
CGRect cellR = [self.tableViewrectForRowAtIndexPath:_currentPlayIndexPath];
if(scrollView.contentOffset.y > cellR.origin.y + cellR.size.height || scrollView.contentOffset.y < cellR.origin.y - scrollView.frame.size.height){
_currentPlayIndexPath = nil;
//Do something when the cell scrolls off screen
}
NSLog(@"-------:%@",NSStringFromCGPoint(scrollView.contentOffset));
}
}