亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

我按老師的敲完之后按按鈕怎么沒反應有人遇到了相同的情況么

我還按老師的視頻重新看了一遍代碼,還是沒發現錯誤

正在回答

1 回答

//

//? 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


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

我按老師的敲完之后按按鈕怎么沒反應有人遇到了相同的情況么

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號