Recently do the project need to achieve this function, although the sense of implementation is not very complicated, but I still do not want to write, because after all, the video app is very fire, and basically have the function of the bomb screen. But found on the internet did not have a lot to choose the third party, so recently wrote a demo, and put on GitHub (click to view)
Which implements my principle I am referring to this blog (click to view)
Achieve the effect:
Barrage Type: Supports scrolling from right to left, supporting middle top and bottom bounce.
Content: Support Emoticons, custom content text size and color
How to: Create a Cfdanmakuview object, configure it, and add it to the view
_danmakuView = [[CFDanmakuView alloc] initWithFrame:rect];_danmakuView.duration = 6.5;_danmakuView.centerDuration = 2.5;_danmakuView.lineHeight = 25;_danmakuView.maxShowLineCount = 15;_danmakuView.maxCenterLineCount = 5;_danmakuView.delegate = self;[self.view addSubview:_danmakuView];
Configure the data for the bullet screen
CFDanmaku* danmaku = [[CFDanmaku alloc] init];[danmakus addObject:danmaku];[_danmakuView prepareDanmakus:danmakus];// 对应视频的时间戳@property(nonatomic, assign) NSTimeInterval timePoint;// 弹幕内容@property(nonatomic, copy) NSAttributedString* contentStr;// 弹幕类型(如果不设置 默认情况下只是从右到左滚动)@property(nonatomic, assign) CFDanmakuPosition position;
Compliance with protocols and implementation of proxy methods
// 获取视频播放时间- (NSTimeInterval)danmakuViewGetPlayTime:(CFDanmakuView *)danmakuView{ if(_slider.value == 1.0) [_danmakuView stop] ; return _slider.value*120.0;}// 是否正在加载视频中- (BOOL)danmakuViewIsBuffering:(CFDanmakuView *)danmakuView{ return NO;}
For specific usage, please refer to demo (click to view)
If you find any bug or have any questions welcome message!
Basic realization and principle introduction of iOS projectile screen