#BarrageDemo
##弹幕
BarrageView *view = [[BarrageView alloc] initWithFrame:CGRectMake(0, 100, 320, 250)];
view.delegate = self;
view.dataSouce = self;
[self.view addSubview:view];
- 返回轨道数(required)
- (NSUInteger)numberOfRowsInTableView:(BarrageView *)barrageView
{
return 5;
}
- 返回自定义cell样式(required)
- (BarrageViewCell *)barrageView:(BarrageView *)barrageView cellForRowAtIndex:(NSInteger)index
{
CustomCell *cell = [CustomCell cellWithBarrageView:barrageView];
cell.model = self.dataArray[index];
return cell;
}
- cell点击代理(optional)
- (void)barrageView:(BarrageView *)barrageView didSelectedCell:(BarrageViewCell *)cell
{
CustomCell *customCell = (CustomCell *)cell;
NSLog(@"你点击了:%@", customCell.model.message);
}
- 即将展示代理(optional)
- (void)barrageView:(BarrageView *)barrageView willDisplayCell:(BarrageViewCell *)cell
{
CustomCell *customCell = (CustomCell *)cell;
NSLog(@"%@即将展示", customCell.model.message);
}
- 展示完成代理(optional)
- (void)barrageView:(BarrageView *)barrageView didEndDisplayingCell:(BarrageViewCell *)cell
{
CustomCell *customCell = (CustomCell *)cell;
NSLog(@"%@展示完成", customCell.model.message);
}
- 插入弹幕消息
[self.barrageView insertBarrages:self.dataArray immediatelyShow:YES];
- 暂停与继续
- (IBAction)stopBtnClicked:(UIButton *)btn
{
btn.selected = !btn.selected;
if (btn.selected) {
[self.barrageView pauseAnimation];
}else {
[self.barrageView resumeAnimation];
}
}
IOS弹幕实现原理及代码分析详见http://www.jianshu.com/p/69b3c388670a 实现效果如下: