// // YMAudioVideoMatchingTransitionView.m // MSYOUPAI // // Created by YoMi on 2024/2/20. // Copyright © 2024 MS. All rights reserved. // #import "YMAudioVideoMatchingTransitionView.h" #import "YMAudioVideoMatchingViewModel.h" @interface YMAudioVideoMatchingTransitionView () /// 音视频匹配VM @property (nonatomic, strong) YMAudioVideoMatchingViewModel *viewModel; /// 过渡动画视图 @property (nonatomic, strong) LOTAnimationView *transitionAnimationView; /// 用户头像动画视图 @property (nonatomic, strong) UIView *userAvatarAnimationView; /// 用户头像视图 @property (nonatomic, strong) UIImageView *userAvatarView; /// 匹配类型图标 @property (nonatomic, strong) UIImageView *matchingTypeIcon; /// 过渡提示标签 @property (nonatomic, strong) UILabel *transitionTipsLb; @end @implementation YMAudioVideoMatchingTransitionView - (void)ym_setupViews{ [self addSubview:self.transitionAnimationView]; [self.transitionAnimationView addSubview:self.userAvatarAnimationView]; [self.userAvatarAnimationView addSubview:self.userAvatarView]; [self.userAvatarAnimationView addSubview:self.matchingTypeIcon]; [self addSubview:self.transitionTipsLb]; [self addSubview:self.countdownLab]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints { [self.transitionAnimationView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.top.equalTo(self); make.width.mas_equalTo(adapt(350)); make.height.mas_equalTo(adapt(350)); }]; [self.userAvatarAnimationView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.transitionAnimationView.mas_centerX); make.centerY.equalTo(self.transitionAnimationView.mas_centerY); }]; [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userAvatarAnimationView).offset(adapt(10)); make.left.equalTo(self.userAvatarAnimationView).offset(adapt(10)); make.right.equalTo(self.userAvatarAnimationView).offset(adapt(-10)); make.bottom.equalTo(self.userAvatarAnimationView).offset(adapt(-10)); make.width.height.mas_equalTo(adapt(80)); }]; [self.matchingTypeIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.userAvatarView.mas_bottom); make.right.equalTo(self.userAvatarView.mas_right); make.width.height.mas_equalTo(adapt(26)); }]; [self.transitionTipsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.transitionAnimationView.mas_bottom).offset(adapt(15)); make.left.equalTo(self).offset(adapt(15)); make.right.equalTo(self).offset(adapt(-15)); make.bottom.equalTo(self); }]; [self.countdownLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.transitionTipsLb.mas_bottom).offset(adapt(20)); make.height.mas_equalTo(adapt(50)); make.left.equalTo(self).offset(adapt(50)); make.right.equalTo(self).offset(adapt(-50)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMAudioVideoMatchingViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; @weakify(self) [[[[RACObserve(self.viewModel, audioVideoMatchingTransitionFileName) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * audioVideoMatchingTransitionFileName) { @strongify(self) [self.transitionAnimationView setAnimationNamed:audioVideoMatchingTransitionFileName inBundle:[NSBundle mainBundle]]; [self.transitionAnimationView play]; }]; [[[[RACObserve(self.viewModel, userAvatar) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userAvatar) { @strongify(self) [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:userAvatar]]; }]; [[[[RACObserve(self.viewModel, matchingTypeIcon) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(UIImage * matchingTypeIcon) { @strongify(self) self.matchingTypeIcon.image = matchingTypeIcon; }]; } - (LOTAnimationView *)transitionAnimationView{ if (!_transitionAnimationView) { _transitionAnimationView = [[LOTAnimationView alloc]init]; _transitionAnimationView.loopAnimation = YES; } return _transitionAnimationView; } - (UIView *)userAvatarAnimationView{ if (!_userAvatarAnimationView) { _userAvatarAnimationView = [[UIView alloc]init]; CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; animation.keyPath = @"transform.scale"; animation.values = @[@1.0,@1.1,@1.15,@1.2,@1.25,@1.3,@1.25,@1.2,@1.15,@1.1,@1.0]; animation.duration = 2; animation.calculationMode = kCAAnimationCubic; animation.repeatCount = MAXFLOAT; [_userAvatarAnimationView.layer addAnimation:animation forKey:nil]; } return _userAvatarAnimationView; } - (UIImageView *)userAvatarView{ if (!_userAvatarView) { _userAvatarView = [[UIImageView alloc]init]; _userAvatarView.contentMode = UIViewContentModeScaleAspectFill; _userAvatarView.backgroundColor = UIColor.lightGrayColor; _userAvatarView.layer.borderWidth = adapt(2); _userAvatarView.layer.borderColor = HexColorFromRGB(0xFFFFFF).CGColor; _userAvatarView.layer.cornerRadius = adapt(80)/2; _userAvatarView.layer.masksToBounds = YES; } return _userAvatarView; } - (UIImageView *)matchingTypeIcon{ if (!_matchingTypeIcon) { _matchingTypeIcon = [[UIImageView alloc]init]; } return _matchingTypeIcon; } - (UILabel *)transitionTipsLb{ if (!_transitionTipsLb) { _transitionTipsLb = [[UILabel alloc]init]; _transitionTipsLb.font = LCBoldFont(13); _transitionTipsLb.textColor = HexColorFromRGB(0xFFFFFF); _transitionTipsLb.textAlignment = NSTextAlignmentCenter; _transitionTipsLb.text = @"正在为您匹配有缘小姐姐,加速中~"; } return _transitionTipsLb; } - (UILabel *)countdownLab{ if(!_countdownLab){ _countdownLab = [[UILabel alloc]init]; _countdownLab.font = LCBoldFont(18); [_countdownLab setBackgroundColor:HexColorFromRGB(0xfd7bc5)]; _countdownLab.textColor = [UIColor whiteColor]; _countdownLab.textAlignment = NSTextAlignmentCenter; _countdownLab.text = @"正在进入速配"; [_countdownLab setHidden:YES]; } return _countdownLab; } @end