Coder Social home page Coder Social logo

barrage's Introduction

Barrage

闲来无事找的弹幕demo原demo地址 感觉存在一些问题而且不可以实时插入新的弹幕, 所以进行了修改 git地址

Image text

功能优化如下:

  1. 通过设置 BulletManager 中的 numOfLines 属性 设置弹道的行数
  2. 弹幕来源通过更改 BulletManager 中的 dataSource设置
  3. 实时加入弹幕
  4. 在原demo的基础上加了弹幕view的重用

调用弹幕只需要执行以下几个方法

//初始化
self.manager = [[BulletManager alloc]init];
self.manager.numOfLines = 10;
__weak typeof(self) weakSelf = self;
self.manager.generrateViewBlock = ^(BulletView *view){

[weakSelf addBarrageView:view];
};

//调用以下方法实现弹幕的实时插入
- (IBAction)addaBarrage:(UIButton *)sender {
[self.manager.dataSource insertObject:[NSString stringWithFormat:@"弹幕 %d", arc4random()%1000] atIndex:0];
[self.manager showNewBullet];
}

//新增一条动画
- (void)addBarrageView:(BulletView *)view {

CGFloat width = [UIScreen mainScreen].bounds.size.width;
view.frame = CGRectMake(width, 150 + view.line * 50, CGRectGetWidth(view.bounds), CGRectGetHeight(view.bounds));
[self.view addSubview:view];
[view startAnimation];
}

//取消弹幕
- (IBAction)Stop:(UIButton *)sender {
[self.manager stop];
}

//开始 (被我改成了按钮重置弹幕数量,里面是一些写死的数据)
- (IBAction)start:(UIButton *)sender {
[self.manager start];
}

barrage's People

Contributors

2232787525 avatar

Watchers

LL avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.