iOS开发--视频模型

2016-12-19  本文已影响26人  一个有个性的女汉子

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

在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;

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

上一篇 下一篇

猜你喜欢

热点阅读