This action will force synchronization from kingly09/KYBarrageKit, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
This is a barrage of rendering library iOS high expansion, for most of the live broadcasting barrage scene.
The company is doing direct business platform, products need to interface with the barrage in the live effect, there are some special animation effects, according to the needs of products, some open source projects combined with the Internet, he made the wheels, write a barrage of live rendering library, since meet the functional requirements of our products and.
NSMutableAttributedString
type support, pictures and text barrage, Emoji emoticons etc.;KYBarrageDisplayTypeImage
type barrage, barrage support custom height;CABasicAnimation
to achieve animation effects to barrage;To achieve some of the basic functions, more follow-up to improve the function......
Effect as shown below:
If there is anything you think is wrong, or have a better suggestion, the above contact can contact me. Thank you very much.
First Download project ,the KYBarrageKit sub folder into the project, import the KYBarrageKit.h
header file in use.
You can add the following line of code to the KYBarrageKit to use the Podfile
pod 'KYBarrageKit'
Use cocoaPods
to manage the third party library, if the computer does not install cocoapods
, please install the cocoapods
. Installation method can refer to: [the latest cocoapods installation] (http://blog.sina.com.cn/s/blog_6ff6523d0102x8dq.html)
#import “KYBarrageKit”
KYBarrageManager *manager
object, and the view add that you want to add a barrage of animation view, as shown below:@interface ViewController ()
@property (strong, nonatomic) KYBarrageManager *manager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor whiteColor];
_manager = [KYBarrageManager manager];
_manager.bindingView = self.view;
_manager.scrollSpeed = 30;
_manager.refreshInterval = 1.0;
}
int a = arc4random() % 100000;
NSString *str = [NSString stringWithFormat:@"I'm coming %d ",a];
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
[attr addAttribute:NSForegroundColorAttributeName value:RandomColor() range:NSMakeRange(0, str.length)];
KYBarrageModel *m = [[KYBarrageModel alloc] initWithBarrageContent:attr];
[_manager showBarrageWithDataSource:m]; // Scroll Barrage
KYBarrageDisplayLocationTypeDefault
Global setting
_manager.displayLocation = KYBarrageDisplayLocationTypeTop;
Or when the sub set barrage
KYBarrageModel *m = [[KYBarrageModel alloc] initWithBarrageContent:attr];
m.displayLocation = _manager. KYBarrageDisplayLocationTypeTop;
Support for the display area of the corresponding NSInteger
enumeration:
KYBarrageDisplayLocationType | value | note |
---|---|---|
KYBarrageDisplayLocationTypeDefault | 0 | the entire display area |
KYBarrageDisplayLocationTypeTop | 1 | the top part |
KYBarrageDisplayLocationTypeCenter | 2 | the middle part |
KYBarrageDisplayLocationTypeBottom | 3 | the bottom part |
KYBarrageDisplayLocationTypeHidden | 4 | Hidden |
Global setting
_manager.scrollDirection = KYBarrageScrollDirectRightToLeft;
Or when the sub set barrage
KYBarrageModel *m = [[KYBarrageModel alloc] initWithBarrageContent:attr];
m.direction = _manager.scrollDirection;
Support for the enumeration of NSInteger
in four directions:
KYBarrageScrollDirection | value | note |
---|---|---|
KYBarrageScrollDirectRightToLeft | 0 | <<<<< |
KYBarrageScrollDirectLeftToRight | 1 | >>>>> |
KYBarrageScrollDirectBottomToTop | 2 | ↑↑↑↑↑ |
KYBarrageScrollDirectTopToBottom | 3 | ↓↓↓↓↓ |
KYBarrageManagerDelegate
, call the -delegate barrageManagerDataSource
dataSet proxy,Open Access Initiative barrage
_manager.delegate = self;
[_manager startScroll]; //Open Access Initiative barrage
Calling method
- (id)barrageManagerDataSource {
int a = arc4random() % 10000;
NSString *str = [NSString stringWithFormat:@"%d digg",a];
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
[attr addAttribute:NSForegroundColorAttributeName value:RandomColor() range:NSMakeRange(0, str.length)];
KYBarrageModel *m = [[KYBarrageModel alloc] initWithBarrageContent:attr];
m.displayLocation = _manager.displayLocation;
m.direction = _manager.scrollDirection;
m.barrageType = KYBarrageDisplayTypeImage;
m.object = [UIImage imageNamed:[NSString stringWithFormat:@"digg_%d",arc4random() % 10]];
return m;
}
[_manager closeBarrage];
// 1. On the screen the barrage is suspended, and stop acquiring new barrage
// 2. The current barrage on the screen to start rolling, and to obtain a new barrage
[_manager pauseScroll];
KYBarrageDisplayTypeDefault
KYBarrageDisplayTypeImage
, can customize other types of KYBarrageScene
.m.barrageType = KYBarrageDisplayTypeImage;
The click event support barrage
If a barrage of type KYBarrageDisplayTypeImage
barrage, please rewrite the ViewController
touchesBegan
method
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
[[_manager barrageScenes] enumerateObjectsUsingBlock:^(BarrageScene * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.layer.presentationLayer hitTest:touchPoint]) {
/* if barrage's type is ` `KYBarrageDisplayTypeImage` `, add your code here*/
NSLog(@"message = %@",obj.model.message.string);
}
}];
}
Such as click inside the DEMO barrage, barrage pause 3S after rolling, can also be extended to other events, as shown below:
If it accidentally gives you help, please do not mean to give it a star, it is the best support for it, thank you very much!
KYBarrageKit is licensed under the MIT protocol. Access to the LICENSE file for more information.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。