ios弹幕解决😂

作者: Hither | 来源:发表于2016-06-20 16:49 被阅读1197次

    最近一直在做直播方面的事情,在做弹幕的时候遇到了一些问题。后来找到了一个相当不错的解决方法,用野狗的SDK,😂。废话就不多说了,大家看下效果~

    整体的项目结构:

    下面简单讲解下实现的过程:

    初始化:
    _wilddog = [[Wilddog alloc] initWithUrl:kWilddogUrl];
        
        _snaps = [[NSMutableArray alloc] init];
        _originFrame = self.view.frame;
    
        [self.wilddog observeEventType:WEventTypeChildAdded withBlock:^(WDataSnapshot *snapshot) {
            
            [self sendLabel:snapshot];
            [self.snaps addObject:snapshot];
            
        }];
    
    发送弹幕:
    - (UILabel *)sendLabel:(WDataSnapshot *)snapshot
    {
        float top = (arc4random()% (int)self.view.frame.size.height)-100;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width, top, 100, 30)];
        label.textColor = [UIColor colorWithRed:arc4random()%255/255.f green:arc4random()%255/255.f blue:arc4random()%255/255.f alpha:1];
        label.text = snapshot.value;
        [UIView animateWithDuration:7 animations:^{
            label.frame = CGRectMake(-label.frame.size.width, top, 100, 30);
        }completion:^(BOOL finished){
            [label removeFromSuperview];
        }];
        [self.view addSubview:label];
        return label;
    }
    

    野狗弹幕下载地址:https://github.com/WildDogTeam/demo-ios-danmu

    相关文章

      网友评论

      本文标题:ios弹幕解决😂

      本文链接:https://www.haomeiwen.com/subject/wlbwdttx.html