我曾经做个视频监控的项目,在tableView里面的每个单元格都有视频监控画面,有这么一个需求,就是,视频播放后,划出屏幕的视频停止播放,只播放屏幕内的视频,废话不说直接上代码
//滑出屏幕停止播放
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[indexArrayenumerateObjectsUsingBlock:^(id _Nonnullobj,NSUIntegeridx,BOOL*_Nonnullstop) {
if(obj !=nil) {
UserObject* user = [[UserObject alloc]init];
user = obj;
CGRectrectInTableView = [self.realtimeTableView rectForRowAtIndexPath: user.operatedCellIndexPath];
CGRectrectInSuperview = [self.realtimeTableViewconvertRect:rectInTableViewtoView:[self.realtimeTableViewsuperview]];
if( rectInSuperview.origin.y >SCREENH-statusHight-44-49|| rectInSuperview.origin.y < - user.currentPlayingCell.np.playerView.frame.size.height) {
BOOLmypla= [user.currentPlayingCell.np isPlaying];
if(mypla ==YES) {
user.currentPlayingCell.bgImage.hidden =NO;
[XLPaymentLoadingHUD hideIn:user.currentPlayingCell.playView];
UIImage* image = [selfsnapshotScreenInView: user.currentPlayingCell.np.playerView];
user.currentPlayingCell.bgImage.image = image;
[user.currentPlayingCell.np stop];
user.currentPlayingCell.plagbtn.hidden =NO;
user.currentPlayingCell.canacleBtn.selected =NO;
[self.realtimeTableViewreloadData];
[user.currentPlayingCell.canacleBtn setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateSelected];
}
}
}
}];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
[indexArrayenumerateObjectsUsingBlock:^(id _Nonnullobj,NSUIntegeridx,BOOL*_Nonnullstop) {
if(obj !=nil) {
UserObject* user = [[UserObject alloc]init];
user = obj;
CGRectrectInTableView = [self.realtimeTableView rectForRowAtIndexPath: user.operatedCellIndexPath];
CGRectrectInSuperview = [self.realtimeTableViewconvertRect:rectInTableViewtoView:[self.realtimeTableViewsuperview]];
if( rectInSuperview.origin.y>SCREENH-statusHight-44-49-30|| rectInSuperview.origin.y+ rectInSuperview.size.height<0) {
BOOLmypla= [user.currentPlayingCell.np isPlaying];
if(mypla ==YES) {
user.currentPlayingCell.bgImage.hidden =NO;
[XLPaymentLoadingHUD hideIn:user.currentPlayingCell.playView];
UIImage* image = [selfsnapshotScreenInView: user.currentPlayingCell.np.playerView];
user.currentPlayingCell.bgImage.image = image;
[user.currentPlayingCell.np stop];
user.currentPlayingCell.plagbtn.hidden =NO;
user.currentPlayingCell.canacleBtn.selected =NO;
[self.realtimeTableViewreloadData];
[user.currentPlayingCell.canacleBtn setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateSelected];
}
}
}
}];
}