XYQuickMatchTopMatchSuccessView.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //
  2. // XYQuickMatchTopMatchSuccessView.m
  3. // Starbuds
  4. //
  5. // Created by gy on 2020/12/4.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYQuickMatchTopMatchSuccessView.h"
  9. @interface XYQuickMatchTopMatchSuccessViewItemView : BaseView
  10. @property (nonatomic, strong) UIImageView *avatarImgView1;
  11. @property (nonatomic, strong) UIImageView *avatarImgView2;
  12. @property (nonatomic, strong) UILabel *nameLab1;
  13. @property (nonatomic, strong) UILabel *disLab;
  14. - (void)setup;
  15. - (void)reload:(XYUserModel *)model1;
  16. @end
  17. @implementation XYQuickMatchTopMatchSuccessViewItemView
  18. - (void)setup{
  19. self.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:0.1];
  20. kViewRadius(self, 12);
  21. _avatarImgView1 = [[UIImageView alloc] init];
  22. _avatarImgView1.contentMode = UIViewContentModeScaleAspectFill;
  23. [self addSubview:_avatarImgView1];
  24. [_avatarImgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.centerY.equalTo(self.mas_centerY).offset(0);
  26. make.left.equalTo(self.mas_left).offset(4);
  27. make.width.offset(16);
  28. make.height.offset(16);
  29. }];
  30. [_avatarImgView1 layoutIfNeeded];
  31. kViewRadius(_avatarImgView1, 8);
  32. _avatarImgView2 = [[UIImageView alloc] init];
  33. _avatarImgView2.contentMode = UIViewContentModeScaleAspectFill;
  34. [self addSubview:_avatarImgView2];
  35. [_avatarImgView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.centerY.equalTo(self.mas_centerY).offset(0);
  37. make.left.equalTo(self.mas_left).offset(17);
  38. make.width.offset(16);
  39. make.height.offset(16);
  40. }];
  41. [_avatarImgView2 layoutIfNeeded];
  42. kViewRadius(_avatarImgView2, 8);
  43. _disLab = [[UILabel alloc] init];
  44. _disLab.font = [UIFont fontWithName:kPFSCFont size:12];
  45. _disLab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  46. _disLab.text = @"匹配成功";
  47. [_disLab sizeToFit];
  48. [self addSubview:_disLab];
  49. [_disLab mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerY.equalTo(self.mas_centerY).offset(0);
  51. make.right.equalTo(self.mas_right).offset(-8);
  52. }];
  53. [_disLab layoutIfNeeded];
  54. _nameLab1 = [[UILabel alloc] init];
  55. _nameLab1.font = [UIFont fontWithName:kPFSCFont size:12];
  56. _nameLab1.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  57. _nameLab1.text = @"-";
  58. [_nameLab1 sizeToFit];
  59. [self addSubview:_nameLab1];
  60. [_nameLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.centerY.equalTo(self.mas_centerY).offset(0);
  62. make.left.equalTo(_avatarImgView2.mas_right).offset(8);
  63. make.right.equalTo(_disLab.mas_left).offset(0);
  64. }];
  65. [_nameLab1 layoutIfNeeded];
  66. }
  67. - (void)reload:(XYUserModel *)model1 {
  68. [self.avatarImgView1 sd_setImageWithURL:[NSURL URLWithString:model1.userAvatar] placeholderImage:placeholderUserMainBgImage(model1.userSex)];
  69. [self.avatarImgView2 sd_setImageWithURL:[NSURL URLWithString:model1.userId] placeholderImage:placeholderUserMainBgImage(model1.userSex)];
  70. self.nameLab1.text = model1.userNo;
  71. }
  72. @end
  73. @interface XYQuickMatchTopMatchSuccessView(){
  74. }
  75. @property (nonatomic, strong) NSMutableArray *dataArrs;
  76. @property (nonatomic, assign) NSInteger loopIndex;
  77. @property (nonatomic, strong) XYQuickMatchTopMatchSuccessViewItemView *itemView1;
  78. @property (nonatomic, strong) XYQuickMatchTopMatchSuccessViewItemView *itemView2;
  79. @property (nonatomic, strong) UIView *tempView;
  80. @property (nonatomic, assign) BOOL isForeground;
  81. @end
  82. @implementation XYQuickMatchTopMatchSuccessView
  83. - (void)setup{
  84. self.hidden = YES;
  85. self.clipsToBounds = YES;
  86. //1.初始化XYQuickMatchTopMatchSuccessViewItemView传入两条数据循环
  87. self.tempView = [[UIView alloc] init];
  88. self.tempView.hidden = YES;
  89. [self addSubview:self.tempView];
  90. XYQuickMatchTopMatchSuccessViewItemView *itemView1 = [[XYQuickMatchTopMatchSuccessViewItemView alloc] init];
  91. self.itemView1 = itemView1;
  92. itemView1.frame = CGRectMake(0, 0, self.width, self.height);
  93. [self addSubview:itemView1];
  94. [itemView1 setup];
  95. XYQuickMatchTopMatchSuccessViewItemView *itemView2 = [[XYQuickMatchTopMatchSuccessViewItemView alloc] init];
  96. self.itemView2 = itemView2;
  97. itemView2.frame = CGRectMake(0, self.height, self.width, self.height);
  98. [self addSubview:itemView2];
  99. [itemView2 setup];
  100. self.isForeground = YES;
  101. self.isViewAppear = YES;
  102. /// APP将要进入活跃状态
  103. [NotificationCenter addObserver:self selector:@selector(appWillEnterForeground:) name:APP_WILL_ENTER_FOREGROUND_NOTIFICATION object:nil];
  104. /// APP将要进入活跃状态
  105. [NotificationCenter addObserver:self selector:@selector(appWillEnterBackground:) name:APP_WILL_ENTER_BACKGROUND_NOTIFICATION object:nil];
  106. }
  107. - (void)appWillEnterForeground:(NSNotification *)notification {
  108. self.isForeground = YES;
  109. }
  110. - (void)appWillEnterBackground:(NSNotification *)notification {
  111. self.isForeground = NO;
  112. }
  113. - (void)setIsViewAppear:(BOOL)isViewAppear{
  114. _isViewAppear = isViewAppear;
  115. [self next];
  116. }
  117. - (void)setIsForeground:(BOOL)isForeground{
  118. _isForeground = isForeground;
  119. [self next];
  120. }
  121. //2.刷新匹配成功的数据
  122. - (void)reload:(NSMutableArray *)dataArrs{
  123. self.dataArrs = dataArrs;
  124. if (!self.dataArrs.count) {
  125. return;
  126. }
  127. self.hidden = NO;
  128. self.loopIndex++;
  129. XYUserModel *model1 = self.dataArrs[self.loopIndex];
  130. if (!model1) { self.loopIndex = 0; }
  131. [self.itemView1 reload:model1];
  132. self.loopIndex++;
  133. XYUserModel *model2 = self.dataArrs[self.loopIndex];
  134. if (!model2) { self.loopIndex = 0; }
  135. [self.itemView2 reload:model2];
  136. [self next];
  137. }
  138. - (void)next{
  139. if (!self.dataArrs.count || !self.isForeground || !self.isViewAppear) {
  140. return;
  141. }
  142. [UIView animateWithDuration:0.5 animations:^{
  143. if (self.itemView1.top == 0) {
  144. self.itemView1.frame = CGRectMake(0, -self.height, self.width, self.height);
  145. self.itemView2.frame = CGRectMake(0, 0, self.width, self.height);
  146. }else if (self.itemView2.top == 0) {
  147. self.itemView2.frame = CGRectMake(0, -self.height, self.width, self.height);
  148. self.itemView1.frame = CGRectMake(0, 0, self.width, self.height);
  149. }
  150. } completion:^(BOOL finished) {
  151. if (self.itemView1.top == -self.height) {
  152. self.loopIndex++;
  153. XYUserModel *model1 = self.dataArrs[self.loopIndex];
  154. if (!model1) { self.loopIndex = 0; }
  155. [self.itemView1 reload:model1];
  156. }
  157. if (self.itemView2.top == -self.height) {
  158. self.loopIndex++;
  159. XYUserModel *model2 = self.dataArrs[self.loopIndex];
  160. if (!model2) { self.loopIndex = 0; }
  161. [self.itemView2 reload:model2];
  162. }
  163. if (self.itemView2.top == 0) {
  164. self.itemView1.frame = CGRectMake(0, self.height, self.width, self.height);
  165. }
  166. if (self.itemView1.top == 0) {
  167. self.itemView2.frame = CGRectMake(0, self.height, self.width, self.height);
  168. }
  169. [UIView animateWithDuration:1.5 animations:^{
  170. self.tempView.frame = CGRectMake(self.tempView.left+1, 0, 1, 1);
  171. } completion:^(BOOL finished) {
  172. [self next];
  173. }];
  174. }];
  175. }
  176. - (void)clear{
  177. self.isForeground = NO;
  178. [self.tempView.layer removeAllSublayers];
  179. [_tempView removeFromSuperview];
  180. _tempView = nil;
  181. [self.itemView1.layer removeAllSublayers];
  182. [_itemView1 removeFromSuperview];
  183. _itemView1 = nil;
  184. [self.itemView2.layer removeAllSublayers];
  185. [_itemView2 removeFromSuperview];
  186. _itemView2 = nil;
  187. [self.layer removeAllSublayers];
  188. [NotificationCenter removeObserver:self name:APP_WILL_ENTER_FOREGROUND_NOTIFICATION object:nil];
  189. [NotificationCenter removeObserver:self name:APP_WILL_ENTER_BACKGROUND_NOTIFICATION object:nil];
  190. }
  191. - (NSMutableArray *)dataArrs{
  192. if (_dataArrs == nil) {
  193. _dataArrs = [[NSMutableArray alloc] init];
  194. }
  195. return _dataArrs;
  196. }
  197. /*
  198. // Only override drawRect: if you perform custom drawing.
  199. // An empty implementation adversely affects performance during animation.
  200. - (void)drawRect:(CGRect)rect {
  201. // Drawing code
  202. }
  203. */
  204. @end