Skip to content

Commit

Permalink
继续修改
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Zong committed Aug 11, 2016
1 parent 644fc45 commit 82afc31
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
62 changes: 54 additions & 8 deletions ZGBarrage/ZGBarrage/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];

// 注意,barrageView跟collectionView一样要有个布局Layout
ZGBarrageFlowLayout *flowLayout = [[ZGBarrageFlowLayout alloc] init];
self.barrageView = [[ZGBarrageView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 300) barrageLayout:flowLayout];

// 制作模拟数据
for (int j= 0; j<10; j++) {
// 模拟数据
for (int j= 0; j<1; j++) {

NSMutableArray *mDataArray = [NSMutableArray array];
for (int i=0; i<9; i++) {
for (int i=0; i<100; i++) {
ZGBarrageItemModel *model = [[ZGBarrageItemModel alloc] init];
if (i%3 == 0) {
model.text = @"奥运加油!";
Expand All @@ -46,16 +47,61 @@ - (void)viewDidLoad {

self.barrageView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.barrageView];



// 测试用例
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
[btn1 setTitle:@"1" forState:UIControlStateNormal];
btn1.backgroundColor = [UIColor redColor];
btn1.tag = 1;
btn1.frame = CGRectMake(20, CGRectGetMaxY(self.barrageView.frame) +50, 80, 40);
[btn1 addTarget:self action:@selector(didBtnPress:) forControlEvents:UIControlEventTouchDragInside];
[self.view addSubview:btn1];

UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
[btn2 setTitle:@"2" forState:UIControlStateNormal];
btn2.backgroundColor = [UIColor orangeColor];
btn2.tag = 2;
btn2.frame = CGRectMake(CGRectGetMaxX(btn1.frame) + 20, btn1.frame.origin.y, 80, 40);
[btn2 addTarget:self action:@selector(didBtnPress:) forControlEvents:UIControlEventTouchDragInside];
[self.view addSubview:btn2];

UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeSystem];
btn3.backgroundColor = [UIColor blueColor];
[btn3 setTitle:@"3" forState:UIControlStateNormal];
btn3.tag = 3;
btn3.frame = CGRectMake(CGRectGetMaxX(btn2.frame) + 20, btn1.frame.origin.y, 80, 40);
[btn3 addTarget:self action:@selector(didBtnPress:) forControlEvents:UIControlEventTouchDragInside];
[self.view addSubview:btn3];

}


- (void)test
- (void)didBtnPress:(UIButton *)btn
{
// UICollectionViewLayout *aa;
// UICollectionViewFlowLayout *b;
// UICollectionView *dd;

[self barrageViewAddDataArrayWithSize:btn.tag];
}


- (void)barrageViewAddDataArrayWithSize:(NSInteger)size
{
NSLog(@"size %zd",size);
NSMutableArray *mDataArray = [NSMutableArray array];
for (int i=0; i<size; i++) {
ZGBarrageItemModel *model = [[ZGBarrageItemModel alloc] init];
if (i%3 == 0) {
model.text = @"奥运加油!";
}else if (i%3 == 1){
model.text = @"中国健儿好厉害~";
}else if(i%3 == 2){
model.text = @"傅园慧,天生带笑感的段子手~";
}

[mDataArray addObject:model];
}

[self.barrageView addDataArray:mDataArray.copy];
}

@end
4 changes: 4 additions & 0 deletions ZGBarrage/ZGBarrage/ZGBarrage/Model/ZGBarrageLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

@class ZGBarrageView;


/**
* 该类(抽象类)一般不直接使用,一般都继承它
*/
@interface ZGBarrageLayout : NSObject

@property (nonatomic, weak) ZGBarrageView *barrageView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ - (void)addMagazine:(NSArray *)magazine

// 添加完数据,通知barrageView将数据显示到屏幕
[self.barrageView reloadDataWithMagazine:tmpMagazine];

// 添加完magazine 通知emitter
// [self.barrageView.emitter start];

}

- (void)removeMagazineWithIndex:(NSInteger)index
Expand Down
11 changes: 11 additions & 0 deletions ZGBarrage/ZGBarrage/ZGBarrage/Model/ZGEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@

@interface ZGEmitter : NSObject <ZGBarrageCellAnimateDelegate2>

/**
* 注意,一定要先调用prepare
*/
- (void)prepare;

/**
* 启动发射
*/
- (void)start;

/**
* 发射一个barrageCell
*/
- (void)emitWithBarrageCell:(ZGBarrageCell *)cell;


Expand Down
1 change: 0 additions & 1 deletion ZGBarrage/ZGBarrage/ZGBarrage/View/ZGBarrageCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ - (void)setupViews
self.textLabel = [[UILabel alloc] init];
self.textLabel.textAlignment = NSTextAlignmentCenter;
self.textLabel.font = [UIFont systemFontOfSize:14];
// self.textLabel.hidden = YES;
[self addSubview:self.textLabel];

}
Expand Down

0 comments on commit 82afc31

Please sign in to comment.