iOS开发--视频模型

前几天写了一个视频局部播放,今天换一种实现方式,也可以实现相同的效果,同样的,下面上代码:

在cell.h中先写两个属性:

@property (nonatomic,strong) UITableView *playVieoTableView;

@property (nonatomic,assign) NSIndexPath *indexPath;

然后在cell.m中对model进行初始化:

- (void) initData{

self.playerModel = [[ZFPlayerModel alloc] init];

weakify(self);

self.playBlock = ^(UIButton *btn){

strongify(self);

self.playerModel.tableView = self.playVieoTableView;

self.playerModel.indexPath = self.indexPath;

self.playerModel.cellImageViewTag = self.bgImgView.tag;

self.playerView.playerModel = self.playerModel;

[self.playerView addPlayerToCellImageView:self.bgImgView];

[self.playerView autoPlayTheVideo];

};

}

并写一个懒加载:

- (ZFPlayerView *)playerView{

if (_playerView == nil) {

_playerView = [ZFPlayerView sharedPlayerView];

}

return _playerView;

}

然后在

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

中重新写:

VideoCell *videoCell = (VideoCell *)cell;

videoCell.indexPath = indexPath;

videoCell.playVieoTableView = self.timelineTableView;

}

return cell;

这样就可以实现和之前写的一样的效果了,快操作试试吧!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容