0

我有在单元格中播放视频的逻辑。

每次您在单元格中播放并快速移动滚动条时,播放器都会再次出现。(因为dequeueReusableCellWithIdentifier)。

我想到保存单元格的部分和行,并询问为什么无论何时cellForRowAtIndexPath激活以显示图层。->layer.hidden = NO;

同样在没有积极结果的糟糕尝试中,当单元格执行以下操作时,隐藏层会消失:

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == playInRow && indexPath.section == playInSection) {
        layer.hidden = YES;
    }
}

我什至尝试在其他功能中支持我:

- (BOOL)isPlayingRowVisible {
    NSArray *indexes = [tableClips indexPathsForVisibleRows];
    for (NSIndexPath *index in indexes) {
        if (index.row == playInRow && index.section == playInSection) {
            return YES;
        }
    }

    return NO;
}

尽管进行了所有尝试,但它并不稳定(有时有效,有时无效),并且仍然会出现问题,以在不属于的单元格中显示图层。

有人知道解决和/或控制此问题的方法吗?

谢谢你的时间。

已编辑

cellForRowAtIndexPath代码。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
            SWTableViewCell * cellV;

            ClipVo * clip = [myArray objectAtIndex:indexPath.row];

            if ([clip.type isEqualToString:@"video"]) {
                cellV = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"cellVideoChat"];

                if (cellV == nil) {
                    [[NSBundle mainBundle] loadNibNamed:@"ChatVideoTableViewCell" owner:self options:nil];
                    cellV = cellVideoChat;

                    UIView *view = [cellV viewWithTag:14];
                    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickBtnChatVideo:)];
                    tapGesture.numberOfTapsRequired = 1;
                    [view addGestureRecognizer:tapGesture];
                }
            }
            if (clip.isPlaying && playerClip.rate != 0.0f && [self isPlayingRowVisible] && indexPath.row == playInRow && indexPath.section == playInSection) {
                layer.hidden = NO;
            }

        return cellV;
}

已编辑 2

将图层添加到单元格

当用户按下单元格内的按钮时

playerClip = [[AVPlayer alloc] initWithURL:url];
layer = [AVPlayerLayer playerLayerWithPlayer:playerClip];
layer.backgroundColor = [UIColor blackColor].CGColor;
UIView *viewContainer = [cell viewWithTag:14];

layer.frame = CGRectMake(0, 0, viewContainer.frame.size.width, viewContainer.frame.size.height);
[layer setVideoGravity:AVLayerVideoGravityResizeAspect];
[viewContainer.layer insertSublayer:layer below:btnPlayVideo.layer];

[playerClip play];
playInRow = indexpath.row;
playInSection = indexpath.section;
4

0 回答 0