视频直播app源码中,不仅有“视频直播模块”,还有“业务模块”“消息模块”等等,其中,在动态发布功能里,选择图片后查看及删除的功能该怎么做呢?云豹直播系统中,关于该功能的源码是这样设置的:
1、选择多张图片后点击图片初始化查看页面,传入图片数组
YBScrollImgVC *scrollImg = [[YBScrollImgVC alloc]init];
scrollImg.imgArr = _pohotArr;
scrollImg.delEvent = ^(NSMutableArray *allArr) {
if (allArr.count > 0) {
_pohotArr = allArr;
_photoImgView.image = _pohotArr[0];
[self changeFrame:YES];
}else{
[self changeFrame:NO];
}
};
[[MXBADelegate sharedAppDelegate]pushViewController:scrollImg animated:YES];
2、视频直播app源码中关于设置顶部视图,图片查看索引、删除按钮、返回按钮的代码
-(void)creatNavi {
UIView *navi = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 64+statusbarHeight)];
navi.backgroundColor = [UIColor blackColor];
[self.view addSubview:navi];
UIButton *retrunBtn = [UIButton buttonWithType:0];
retrunBtn.frame = CGRectMake(10, 25+statusbarHeight, 30, 30);
[retrunBtn setImage:[UIImage imageNamed:@"white_backImg"] forState:0];
[retrunBtn addTarget:self action:@selector(returnBtnClick) forControlEvents:UIControlEventTouchUpInside];
[navi addSubview:retrunBtn];
indexLb = [[UILabel alloc]init];
indexLb.frame = CGRectMake(100, 22+statusbarHeight, 80, 30);
indexLb.textColor = [UIColor whiteColor];
indexLb.font = [UIFont systemFontOfSize:15];
indexLb.textAlignment = NSTextAlignmentCenter;
indexLb.text =[NSString stringWithFormat:@"%ld/%ld",currentIndex+1,self.imgArr.count];
[navi addSubview:indexLb];
indexLb.centerX = navi.centerX;
_deleteBtn = [UIButton buttonWithType:0];
_deleteBtn.frame = CGRectMake(_window_width-60, 22+statusbarHeight, 40, 40);
[_deleteBtn setImage:[UIImage imageNamed:@"trends删除white"] forState:0];
_deleteBtn.titleLabel.font = [UIFont systemFontOfSize:16];
[_deleteBtn addTarget:self action:@selector(deleteBtnClick) forControlEvents:UIControlEventTouchUpInside];
[navi addSubview:_deleteBtn];
}
3、设置主显示页面,scorllview实现,设置宽度为整个屏幕宽x图片数量
backScroll = [[UIScrollView alloc]init];
backScroll.frame = CGRectMake(0, 64+statusbarHeight, _window_width, contentHeight);
backScroll.contentSize = CGSizeMake(_window_width *self.imgArr.count, contentHeight);
backScroll.pagingEnabled = YES;
backScroll.delegate = self;
[self.view addSubview:backScroll];
4、设置页面图片,添加相应imageview
-(void)setAllImg{
for ( int i = 0; i < self.imgArr.count; i ++) {
UIImageView *img = [[UIImageView alloc]init];
img.frame = CGRectMake(i * _window_width, 0, _window_width, contentHeight);
img.image = self.imgArr[i];
img.contentMode = UIViewContentModeScaleAspectFit;
[backScroll addSubview:img];
}
}
5、关于左右滑动时修改图片索引、记录当前索引的视频直播app源码
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat contentx = scrollView.contentOffset.x;
int index = contentx/_window_width;
NSLog(@"当前第几页-------:%d",index);
currentIndex = index;
indexLb.text =[NSString stringWithFormat:@"%ld/%ld",currentIndex+1,self.imgArr.count];
}
6、视频直播app源码中关于“当点击删除时,删除掉图片数组内相应的索引,并且移除scrollview上子页面,当数组内图片大于1张时,重新铺数据,展示图片,当图片个数为0时,返回上级页面并传回图片数组”的设置
-(void)deleteBtnClick{
[self.imgArr removeObjectAtIndex:currentIndex];
[backScroll removeAllSubViews];
if (self.imgArr.count > 0) {
[self setAllImg];
backScroll.contentSize = CGSizeMake(self.imgArr.count *_window_width, contentHeight);
backScroll.contentOffset = CGPointMake(currentIndex *_window_width, 0);
indexLb.text =[NSString stringWithFormat:@"%ld/%ld",currentIndex+1,self.imgArr.count];
}else{
if (self.delEvent) {
self.delEvent(self.imgArr);
}
[[MXBADelegate sharedAppDelegate]popViewController:YES];
}
}
7、关于“当点击返回时,传回相应的数组图片便于操作”的视频直播app源码
-(void)returnBtnClick{
if (self.delEvent) {
self.delEvent(self.imgArr);
}
[[MXBADelegate sharedAppDelegate]popViewController:YES];
}
在视频直播app源码中,动态发布功能模块的代码除了上面我们说的这些外,还有很多部分,以后会慢慢放出的,视频直播app源码是比较复杂的源码,牵扯到音视频、牵扯到推拉流,在这条道路上,我们愿意与大家一起进步。
声明:以上内容为作者:云豹网络科技原创,未经作者本人同意,禁止转载,否则将追究相关法律责任