我按老师的敲完之后按按钮怎么没反应有人遇到了相同的情况么
我还按老师的视频重新看了一遍代码,还是没发现错误
我还按老师的视频重新看了一遍代码,还是没发现错误
2017-09-23
//
// BulletManager.m
// CommentDemo
//
// Created by MacBook on 2017/12/1.
// Copyright © 2017年 SimonWest. All rights reserved.
//
#import "BulletManager.h"
#import "BulletView.h"
@interface BulletManager()
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSMutableArray *bulletComment;
@property (nonatomic, strong) NSMutableArray *bulletViews;
@property (nonatomic, assign) BOOL bStopAnimation;
@end
@implementation BulletManager
- (instancetype)init {
if(self = [super init]) {
self.bStopAnimation = YES;
}
return self;
}
- (void)start {
if(!self.bStopAnimation) {
return;
}
self.bStopAnimation = NO;
[self.bulletComment removeAllObjects];
[self.bulletComment addObjectsFromArray:self.dataSource];
[self initBulletComment];
}
- (void)stop {
if(self.bStopAnimation) {
return;
}
self.bStopAnimation = YES;
[self.bulletViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
BulletView *view = obj;
[view stopAnimation];
view = nil;
}];
[self.bulletViews removeAllObjects];
}
- (void)initBulletComment {
NSMutableArray *trajectorys = [NSMutableArray arrayWithArray:@[@(0),@(1),@(2)]];
for (int i = 0; i < 3; i++) {
if(self.bulletComment.count <= 0) {
break;
}
NSInteger index = arc4random() % trajectorys.count;
int trajectory = [[trajectorys objectAtIndex:index] intValue];
[trajectorys removeObjectAtIndex:index];
NSString *comment = [self.bulletComment firstObject];
[self.bulletComment removeObject:comment];
[self createBulletView:comment trajectory:trajectory];
}
}
- (void)createBulletView:(NSString *)comment trajectory:(int)trajectory {
if(self.bStopAnimation) {
return;
}
BulletView *bulletView = [[BulletView alloc] initWithComment:comment];
bulletView.trajectory = trajectory;
__weak typeof(bulletView) weakView = bulletView;
__weak typeof(self) weakSelf = self;
bulletView.moveStatusBlock = ^(MoveStataus status){
if(weakSelf.bStopAnimation) {
return ;
}
switch (status) {
case Start:{
[weakSelf.bulletViews addObject:weakView];
break;
}
case Enter:{
NSString *comment = [weakSelf nextComment];
if(comment) {
[weakSelf createBulletView:comment trajectory:trajectory];
}
break;
}
case End:{
if([weakSelf.bulletViews containsObject:weakView]) {
[weakView stopAnimation];
[weakSelf.bulletViews removeObject:weakView];
}
if(weakSelf.bulletViews.count == 0) {
weakSelf.bStopAnimation = YES;
[weakSelf start];
}
break;
}
}
};
if(self.generateViewBlock) {
self.generateViewBlock(bulletView);
}
}
- (NSString *)nextComment {
if(self.bulletComment.count == 0) {
return nil;
}
NSString *comment = [self.bulletComment firstObject];
if(comment) {
[self.bulletComment removeObjectAtIndex:0];
}
return comment;
}
- (NSMutableArray *)dataSource {
if(!_dataSource) {
_dataSource = [NSMutableArray arrayWithObjects:@"弹幕1=========",@"弹幕2=========",@"弹幕3===========================",@"弹幕4=========",@"弹幕5=========",@"弹幕6=========",@"弹幕7==", nil];
}
return _dataSource;
}
- (NSMutableArray *)bulletComment {
if(!_bulletComment) {
_bulletComment = [NSMutableArray array];
}
return _bulletComment;
}
- (NSMutableArray *)bulletViews {
if(!_bulletViews) {
_bulletViews = [NSMutableArray array];
}
return _bulletViews;
}
@end
举报