Skip to content

Commit

Permalink
基本完成,遗留reset功能
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Zong committed Aug 14, 2016
1 parent de5ed20 commit 3a9a6af
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 24 deletions.
4 changes: 4 additions & 0 deletions ZGBarrage/ZGBarrage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
EF176A711D5969250060DAE6 /* ZGMagazine.m in Sources */ = {isa = PBXBuildFile; fileRef = EF176A701D5969250060DAE6 /* ZGMagazine.m */; };
EF265DC91D60508700EC0D00 /* Zong.jpg in Resources */ = {isa = PBXBuildFile; fileRef = EF265DC81D60508700EC0D00 /* Zong.jpg */; settings = {ASSET_TAGS = (); }; };
EF2C5EE81D5865E300049AD7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EF2C5EE71D5865E300049AD7 /* main.m */; };
EF2C5EEB1D5865E300049AD7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EF2C5EEA1D5865E300049AD7 /* AppDelegate.m */; };
EF2C5EEE1D5865E300049AD7 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EF2C5EED1D5865E300049AD7 /* ViewController.m */; };
Expand Down Expand Up @@ -46,6 +47,7 @@
/* Begin PBXFileReference section */
EF176A6F1D5969250060DAE6 /* ZGMagazine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZGMagazine.h; sourceTree = "<group>"; };
EF176A701D5969250060DAE6 /* ZGMagazine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZGMagazine.m; sourceTree = "<group>"; };
EF265DC81D60508700EC0D00 /* Zong.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Zong.jpg; sourceTree = "<group>"; };
EF2C5EE31D5865E200049AD7 /* ZGBarrage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZGBarrage.app; sourceTree = BUILT_PRODUCTS_DIR; };
EF2C5EE71D5865E300049AD7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
EF2C5EE91D5865E300049AD7 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -145,6 +147,7 @@
EF2C5EE61D5865E300049AD7 /* Supporting Files */ = {
isa = PBXGroup;
children = (
EF265DC81D60508700EC0D00 /* Zong.jpg */,
EF4708C91D5B331E00A5DE64 /* 弹幕效果展示.gif */,
EF2C5EE71D5865E300049AD7 /* main.m */,
);
Expand Down Expand Up @@ -322,6 +325,7 @@
files = (
EF2C5EF61D5865E300049AD7 /* LaunchScreen.storyboard in Resources */,
EF2C5EF31D5865E300049AD7 /* Assets.xcassets in Resources */,
EF265DC91D60508700EC0D00 /* Zong.jpg in Resources */,
EF2C5EF11D5865E300049AD7 /* Main.storyboard in Resources */,
EF4708CA1D5B331E00A5DE64 /* 弹幕效果展示.gif in Resources */,
);
Expand Down
41 changes: 38 additions & 3 deletions ZGBarrage/ZGBarrage/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];

// 宣传口号~
UILabel *titleLable = [[UILabel alloc] init];
titleLable.text = @"可以点击的弹幕!";
titleLable.backgroundColor = [UIColor blackColor];
titleLable.textColor = [UIColor yellowColor];
titleLable.textAlignment = NSTextAlignmentCenter;
titleLable.font = [UIFont systemFontOfSize:20];
titleLable.frame = CGRectMake((self.view.bounds.size.width- 200) / 2.0, 50, 200, 40);
[self.view addSubview:titleLable];




// 使用样例
// 注意,barrageView跟collectionView一样要有个布局Layout
ZGBarrageFlowLayout *flowLayout = [[ZGBarrageFlowLayout alloc] init];
self.barrageView = [[ZGBarrageView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 300) barrageLayout:flowLayout];
Expand All @@ -30,8 +44,6 @@ - (void)viewDidLoad {
// [self barrageViewAddDataArrayWithSize:7];
// [self barrageViewAddDataArrayWithSize:4];



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

Expand Down Expand Up @@ -62,15 +74,38 @@ - (void)viewDidLoad {
[btn3 addTarget:self action:@selector(didBtnPress:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn3];


UIButton *btn4 = [UIButton buttonWithType:UIButtonTypeSystem];
btn4.backgroundColor = [UIColor lightGrayColor];
[btn4 setTitle:@"发自己弹幕" forState:UIControlStateNormal];
btn4.tag = 4;
btn4.frame = CGRectMake(btn1.frame.origin.x, CGRectGetMaxY(btn1.frame) + 20, 80, 40);
[btn4 addTarget:self action:@selector(didBtnPress:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn4];

}


- (void)didBtnPress:(UIButton *)btn
{
[self barrageViewAddDataArrayWithSize:btn.tag];
if (btn.tag == 4) { // 添加自己的弹幕
[self barrageViewAddMineItemModel];

}else { // 添加别人的弹幕

[self barrageViewAddDataArrayWithSize:btn.tag];
}

}


- (void)barrageViewAddMineItemModel
{
ZGBarrageItemModel *mineItemModel = [[ZGBarrageItemModel alloc] init];
mineItemModel.text = @"宗根的弹幕";
[self.barrageView addMineItemModel:mineItemModel];
}

- (void)barrageViewAddDataArrayWithSize:(NSInteger)size
{
NSMutableArray *mDataArray = [NSMutableArray array];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@

@property (nonatomic, assign) NSInteger maxCount;

// 用于缓存,我自己发的弹幕
@property(nonatomic, strong) NSMutableArray *mineItemModelsArray;


/**
* 构造器
*/
+ (instancetype)barrageViewDataSourceImplementWithBarrageView:(ZGBarrageView *)barrageView;

@property (nonatomic, weak) ZGBarrageView *barrageView;

/**
* 设置,并显示弹幕模型数组,注意数组元素类型一定要ZGBarrageItemModel
* 注意,此方法用于添加--自己发的弹幕
*/
- (void)addMineItemModel:(ZGBarrageItemModel *)mineItemModel;

/**
* 给弹幕上弹匣
* magazine:中文意思 -- 弹匣
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@ - (instancetype)init
{
if (self = [super init]) {
_magazinesArray = [NSMutableArray array];
_mineItemModelsArray = [NSMutableArray array];
}
return self;
}

- (void)addMineItemModel:(ZGBarrageItemModel *)mineItemModel
{
// 上锁
[self.mineItemModelsArray addObject:mineItemModel];

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

}


- (void)addMagazine:(NSArray *)magazine
{
// 必须上锁
Expand Down Expand Up @@ -70,6 +82,7 @@ - (void)removeMagazineWithIndex:(NSInteger)index

if (self.magazinesArray.count == 0) {
self.currentIndex = 0;
[self.barrageView.emitter resetSectionLastedIndexPathDic];
}
}
}
Expand Down Expand Up @@ -99,7 +112,7 @@ - (ZGBarrageItemModel *)getItemModelWithIndexPath:(NSIndexPath *)indexPath
NSInteger normalIndex = indexPath.item * maxRows + indexPath.section;

// 2,必须注意indexPath必须是有效的
if (normalIndex >= 0 && normalIndex < self.maxCount - 1) { // 有效
if (normalIndex >= 0 && normalIndex < self.maxCount) { // 有效

//3,一维index 转换成 在哪个magazine的第几个index
NSInteger indexOfMagazine = 0;
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 @@ -29,11 +29,22 @@

@property (nonatomic, strong) ZGMagazine *magazine;

- (void)resetSectionLastedIndexPathDic;


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


/**
* 发射自己发的弹幕
*/
- (void)sendMineItemModelsArray:(NSMutableArray *)mineItemModelsArray;



/**
* 启动发射
*/
Expand Down
Loading

0 comments on commit 3a9a6af

Please sign in to comment.