MoreToolsView.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // MoreToolsView.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 17/4/5.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "MoreToolsView.h"
  9. #import "MoreToolsCell.h"
  10. @interface MoreToolsView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  11. {
  12. GlobalVariables *_BuguLive;
  13. }
  14. @property(nonatomic, strong) UIView * backGroundView;
  15. @property(nonatomic, strong) NSMutableArray * toolsArray;
  16. @property (nonatomic, strong) UICollectionView *toolsCollectionView;
  17. @end
  18. @implementation MoreToolsView
  19. - (instancetype)initWithFrame:(CGRect)frame
  20. {
  21. if (self = [super initWithFrame:frame])
  22. {
  23. _BuguLive = [GlobalVariables sharedInstance];
  24. [self loadToolsArr];
  25. [self createToolCollection];
  26. }
  27. return self;
  28. }
  29. - (NSMutableArray *) toolsArray
  30. {
  31. if (_toolsArray == nil)
  32. {
  33. _toolsArray = [NSMutableArray array];
  34. }
  35. return _toolsArray;
  36. }
  37. - (void)loadToolsArr
  38. {
  39. [self.toolsArray removeAllObjects];
  40. if ([_BuguLive.appModel.shopping_goods integerValue]== 1)
  41. {
  42. ToolsModel * model = [[ToolsModel alloc] init];
  43. model.imageStr = @"lr_starShop_normal";
  44. model.selectedImageStr = @"lr_starShop_selected";
  45. model.title = ASLocalizedString(@"星店");
  46. [self.toolsArray addObject:model];
  47. }
  48. if (_BuguLive.appModel.open_podcast_goods == 1)
  49. {
  50. ToolsModel * model = [[ToolsModel alloc] init];
  51. model.imageStr = @"lr_myShop_normal";
  52. model.selectedImageStr = @"lr_myShop_selected";
  53. model.title = ASLocalizedString(@"小店");
  54. [self.toolsArray addObject:model];
  55. }
  56. }
  57. - (void)createToolCollection
  58. {
  59. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0,self.width, kScreenH-120)];
  60. view.backgroundColor = [UIColor clearColor];
  61. [self addSubview:view];
  62. _backGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenH-120-kDefaultMargin, self.width, 120)];
  63. self.backGroundView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.2];
  64. self.backGroundView.alpha = 0.5;
  65. [self addSubview:_backGroundView];
  66. self.backGroundView.layer.cornerRadius = kCornerRadius;
  67. self.backGroundView.layer.masksToBounds = YES;
  68. //毛玻璃效果
  69. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  70. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  71. effectView.frame = CGRectMake(0,kScreenH-120-kDefaultMargin, self.width, 120);
  72. [self addSubview:effectView];
  73. effectView.layer.cornerRadius = kCornerRadius;
  74. effectView.layer.masksToBounds = YES;
  75. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  76. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  77. layout.itemSize = CGSizeMake(74, 110);
  78. layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
  79. layout.minimumLineSpacing = 0;
  80. layout.minimumInteritemSpacing = 0;
  81. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  82. _toolsCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, kScreenH-120-kDefaultMargin, self.width, 120) collectionViewLayout:layout];
  83. _toolsCollectionView.backgroundColor = [UIColor clearColor];
  84. _toolsCollectionView.delegate = self;
  85. _toolsCollectionView.dataSource = self;
  86. _toolsCollectionView.showsHorizontalScrollIndicator = NO; //关闭滚动线
  87. _toolsCollectionView.alwaysBounceHorizontal = YES; //总是允许横向滚动
  88. [_toolsCollectionView registerNib:[UINib nibWithNibName:@"MoreToolsCell" bundle:nil] forCellWithReuseIdentifier:@"MoreToolsCell"];
  89. [self addSubview:_toolsCollectionView];
  90. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidenView)];
  91. [view addGestureRecognizer:tap];
  92. }
  93. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  94. {
  95. return self.toolsArray.count;
  96. }
  97. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  98. {
  99. MoreToolsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MoreToolsCell" forIndexPath:indexPath];
  100. cell.model = self.toolsArray[indexPath.item];
  101. return cell;
  102. }
  103. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  104. {
  105. ToolsModel * model = self.toolsArray[indexPath.item];
  106. self.title = model.title;
  107. [self collectionView:_toolsCollectionView didHighlightItemAtIndexPath:indexPath];
  108. if (_delegate && [_delegate respondsToSelector:@selector(clickMoreToolsView:andToolsModel:)])
  109. {
  110. [_delegate clickMoreToolsView:self andToolsModel:model];
  111. }
  112. [UIView animateWithDuration:0.5 animations:^{
  113. self.transform = CGAffineTransformIdentity;
  114. } completion:^(BOOL finished) {
  115. self.hidden = YES;
  116. [self collectionView:_toolsCollectionView didUnhighlightItemAtIndexPath:indexPath];
  117. }];
  118. }
  119. - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
  120. {
  121. return YES;
  122. }
  123. - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
  124. {
  125. MoreToolsCell * cell = (MoreToolsCell *)[collectionView cellForItemAtIndexPath:indexPath];
  126. ToolsModel * model = self.toolsArray[indexPath.item];
  127. cell.toolsImageView.image = [UIImage imageNamed:model.selectedImageStr];
  128. }
  129. - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
  130. {
  131. MoreToolsCell * cell = (MoreToolsCell *)[collectionView cellForItemAtIndexPath:indexPath];
  132. ToolsModel * model = self.toolsArray[indexPath.item];
  133. cell.toolsImageView.image = [UIImage imageNamed:model.imageStr];
  134. }
  135. - (void)hidenView
  136. {
  137. [UIView animateWithDuration:0.5 animations:^{
  138. self.transform = CGAffineTransformIdentity;
  139. } completion:^(BOOL finished) {
  140. self.hidden = YES;
  141. if (_delegate && [_delegate respondsToSelector:@selector(clickCancleWithMoreToolsView:)])
  142. {
  143. [_delegate clickCancleWithMoreToolsView:self];
  144. }
  145. }];
  146. }
  147. @end