// // XYQuickMatchTopMatchSuccessView.m // Starbuds // // Created by gy on 2020/12/4. // Copyright © 2020 翟玉磊. All rights reserved. // #import "XYQuickMatchTopMatchSuccessView.h" @interface XYQuickMatchTopMatchSuccessViewItemView : BaseView @property (nonatomic, strong) UIImageView *avatarImgView1; @property (nonatomic, strong) UIImageView *avatarImgView2; @property (nonatomic, strong) UILabel *nameLab1; @property (nonatomic, strong) UILabel *disLab; - (void)setup; - (void)reload:(XYUserModel *)model1; @end @implementation XYQuickMatchTopMatchSuccessViewItemView - (void)setup{ self.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:0.1]; kViewRadius(self, 12); _avatarImgView1 = [[UIImageView alloc] init]; _avatarImgView1.contentMode = UIViewContentModeScaleAspectFill; [self addSubview:_avatarImgView1]; [_avatarImgView1 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.mas_centerY).offset(0); make.left.equalTo(self.mas_left).offset(4); make.width.offset(16); make.height.offset(16); }]; [_avatarImgView1 layoutIfNeeded]; kViewRadius(_avatarImgView1, 8); _avatarImgView2 = [[UIImageView alloc] init]; _avatarImgView2.contentMode = UIViewContentModeScaleAspectFill; [self addSubview:_avatarImgView2]; [_avatarImgView2 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.mas_centerY).offset(0); make.left.equalTo(self.mas_left).offset(17); make.width.offset(16); make.height.offset(16); }]; [_avatarImgView2 layoutIfNeeded]; kViewRadius(_avatarImgView2, 8); _disLab = [[UILabel alloc] init]; _disLab.font = [UIFont fontWithName:kPFSCFont size:12]; _disLab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1]; _disLab.text = @"匹配成功"; [_disLab sizeToFit]; [self addSubview:_disLab]; [_disLab mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.mas_centerY).offset(0); make.right.equalTo(self.mas_right).offset(-8); }]; [_disLab layoutIfNeeded]; _nameLab1 = [[UILabel alloc] init]; _nameLab1.font = [UIFont fontWithName:kPFSCFont size:12]; _nameLab1.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1]; _nameLab1.text = @"-"; [_nameLab1 sizeToFit]; [self addSubview:_nameLab1]; [_nameLab1 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.mas_centerY).offset(0); make.left.equalTo(_avatarImgView2.mas_right).offset(8); make.right.equalTo(_disLab.mas_left).offset(0); }]; [_nameLab1 layoutIfNeeded]; } - (void)reload:(XYUserModel *)model1 { [self.avatarImgView1 sd_setImageWithURL:[NSURL URLWithString:model1.userAvatar] placeholderImage:placeholderUserMainBgImage(model1.userSex)]; [self.avatarImgView2 sd_setImageWithURL:[NSURL URLWithString:model1.userId] placeholderImage:placeholderUserMainBgImage(model1.userSex)]; self.nameLab1.text = model1.userNo; } @end @interface XYQuickMatchTopMatchSuccessView(){ } @property (nonatomic, strong) NSMutableArray *dataArrs; @property (nonatomic, assign) NSInteger loopIndex; @property (nonatomic, strong) XYQuickMatchTopMatchSuccessViewItemView *itemView1; @property (nonatomic, strong) XYQuickMatchTopMatchSuccessViewItemView *itemView2; @property (nonatomic, strong) UIView *tempView; @property (nonatomic, assign) BOOL isForeground; @end @implementation XYQuickMatchTopMatchSuccessView - (void)setup{ self.hidden = YES; self.clipsToBounds = YES; //1.初始化XYQuickMatchTopMatchSuccessViewItemView传入两条数据循环 self.tempView = [[UIView alloc] init]; self.tempView.hidden = YES; [self addSubview:self.tempView]; XYQuickMatchTopMatchSuccessViewItemView *itemView1 = [[XYQuickMatchTopMatchSuccessViewItemView alloc] init]; self.itemView1 = itemView1; itemView1.frame = CGRectMake(0, 0, self.width, self.height); [self addSubview:itemView1]; [itemView1 setup]; XYQuickMatchTopMatchSuccessViewItemView *itemView2 = [[XYQuickMatchTopMatchSuccessViewItemView alloc] init]; self.itemView2 = itemView2; itemView2.frame = CGRectMake(0, self.height, self.width, self.height); [self addSubview:itemView2]; [itemView2 setup]; self.isForeground = YES; self.isViewAppear = YES; /// APP将要进入活跃状态 [NotificationCenter addObserver:self selector:@selector(appWillEnterForeground:) name:APP_WILL_ENTER_FOREGROUND_NOTIFICATION object:nil]; /// APP将要进入活跃状态 [NotificationCenter addObserver:self selector:@selector(appWillEnterBackground:) name:APP_WILL_ENTER_BACKGROUND_NOTIFICATION object:nil]; } - (void)appWillEnterForeground:(NSNotification *)notification { self.isForeground = YES; } - (void)appWillEnterBackground:(NSNotification *)notification { self.isForeground = NO; } - (void)setIsViewAppear:(BOOL)isViewAppear{ _isViewAppear = isViewAppear; [self next]; } - (void)setIsForeground:(BOOL)isForeground{ _isForeground = isForeground; [self next]; } //2.刷新匹配成功的数据 - (void)reload:(NSMutableArray *)dataArrs{ self.dataArrs = dataArrs; if (!self.dataArrs.count) { return; } self.hidden = NO; self.loopIndex++; XYUserModel *model1 = self.dataArrs[self.loopIndex]; if (!model1) { self.loopIndex = 0; } [self.itemView1 reload:model1]; self.loopIndex++; XYUserModel *model2 = self.dataArrs[self.loopIndex]; if (!model2) { self.loopIndex = 0; } [self.itemView2 reload:model2]; [self next]; } - (void)next{ if (!self.dataArrs.count || !self.isForeground || !self.isViewAppear) { return; } [UIView animateWithDuration:0.5 animations:^{ if (self.itemView1.top == 0) { self.itemView1.frame = CGRectMake(0, -self.height, self.width, self.height); self.itemView2.frame = CGRectMake(0, 0, self.width, self.height); }else if (self.itemView2.top == 0) { self.itemView2.frame = CGRectMake(0, -self.height, self.width, self.height); self.itemView1.frame = CGRectMake(0, 0, self.width, self.height); } } completion:^(BOOL finished) { if (self.itemView1.top == -self.height) { self.loopIndex++; XYUserModel *model1 = self.dataArrs[self.loopIndex]; if (!model1) { self.loopIndex = 0; } [self.itemView1 reload:model1]; } if (self.itemView2.top == -self.height) { self.loopIndex++; XYUserModel *model2 = self.dataArrs[self.loopIndex]; if (!model2) { self.loopIndex = 0; } [self.itemView2 reload:model2]; } if (self.itemView2.top == 0) { self.itemView1.frame = CGRectMake(0, self.height, self.width, self.height); } if (self.itemView1.top == 0) { self.itemView2.frame = CGRectMake(0, self.height, self.width, self.height); } [UIView animateWithDuration:1.5 animations:^{ self.tempView.frame = CGRectMake(self.tempView.left+1, 0, 1, 1); } completion:^(BOOL finished) { [self next]; }]; }]; } - (void)clear{ self.isForeground = NO; [self.tempView.layer removeAllSublayers]; [_tempView removeFromSuperview]; _tempView = nil; [self.itemView1.layer removeAllSublayers]; [_itemView1 removeFromSuperview]; _itemView1 = nil; [self.itemView2.layer removeAllSublayers]; [_itemView2 removeFromSuperview]; _itemView2 = nil; [self.layer removeAllSublayers]; [NotificationCenter removeObserver:self name:APP_WILL_ENTER_FOREGROUND_NOTIFICATION object:nil]; [NotificationCenter removeObserver:self name:APP_WILL_ENTER_BACKGROUND_NOTIFICATION object:nil]; } - (NSMutableArray *)dataArrs{ if (_dataArrs == nil) { _dataArrs = [[NSMutableArray alloc] init]; } return _dataArrs; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end