YMAudioVideoMatchingTransitionView.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // YMAudioVideoMatchingTransitionView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/20.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAudioVideoMatchingTransitionView.h"
  9. #import "YMAudioVideoMatchingViewModel.h"
  10. @interface YMAudioVideoMatchingTransitionView ()
  11. /// 音视频匹配VM
  12. @property (nonatomic, strong) YMAudioVideoMatchingViewModel *viewModel;
  13. /// 过渡动画视图
  14. @property (nonatomic, strong) LOTAnimationView *transitionAnimationView;
  15. /// 用户头像动画视图
  16. @property (nonatomic, strong) UIView *userAvatarAnimationView;
  17. /// 用户头像视图
  18. @property (nonatomic, strong) UIImageView *userAvatarView;
  19. /// 匹配类型图标
  20. @property (nonatomic, strong) UIImageView *matchingTypeIcon;
  21. /// 过渡提示标签
  22. @property (nonatomic, strong) UILabel *transitionTipsLb;
  23. @end
  24. @implementation YMAudioVideoMatchingTransitionView
  25. - (void)ym_setupViews{
  26. [self addSubview:self.transitionAnimationView];
  27. [self.transitionAnimationView addSubview:self.userAvatarAnimationView];
  28. [self.userAvatarAnimationView addSubview:self.userAvatarView];
  29. [self.userAvatarAnimationView addSubview:self.matchingTypeIcon];
  30. [self addSubview:self.transitionTipsLb];
  31. [self addSubview:self.countdownLab];
  32. [self setNeedsUpdateConstraints];
  33. [self updateConstraintsIfNeeded];
  34. }
  35. - (void)updateConstraints {
  36. [self.transitionAnimationView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.centerX.equalTo(self.mas_centerX);
  38. make.top.equalTo(self);
  39. make.width.mas_equalTo(adapt(350));
  40. make.height.mas_equalTo(adapt(350));
  41. }];
  42. [self.userAvatarAnimationView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.centerX.equalTo(self.transitionAnimationView.mas_centerX);
  44. make.centerY.equalTo(self.transitionAnimationView.mas_centerY);
  45. }];
  46. [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.top.equalTo(self.userAvatarAnimationView).offset(adapt(10));
  48. make.left.equalTo(self.userAvatarAnimationView).offset(adapt(10));
  49. make.right.equalTo(self.userAvatarAnimationView).offset(adapt(-10));
  50. make.bottom.equalTo(self.userAvatarAnimationView).offset(adapt(-10));
  51. make.width.height.mas_equalTo(adapt(80));
  52. }];
  53. [self.matchingTypeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.bottom.equalTo(self.userAvatarView.mas_bottom);
  55. make.right.equalTo(self.userAvatarView.mas_right);
  56. make.width.height.mas_equalTo(adapt(26));
  57. }];
  58. [self.transitionTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.top.equalTo(self.transitionAnimationView.mas_bottom).offset(adapt(15));
  60. make.left.equalTo(self).offset(adapt(15));
  61. make.right.equalTo(self).offset(adapt(-15));
  62. make.bottom.equalTo(self);
  63. }];
  64. [self.countdownLab mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.equalTo(self.transitionTipsLb.mas_bottom).offset(adapt(20));
  66. make.height.mas_equalTo(adapt(50));
  67. make.left.equalTo(self).offset(adapt(50));
  68. make.right.equalTo(self).offset(adapt(-50));
  69. }];
  70. [super updateConstraints];
  71. }
  72. - (void)ym_bindViewModel:(YMAudioVideoMatchingViewModel *)viewModel{
  73. if (!viewModel) {
  74. return;
  75. }
  76. _viewModel = viewModel;
  77. @weakify(self)
  78. [[[[RACObserve(self.viewModel, audioVideoMatchingTransitionFileName) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * audioVideoMatchingTransitionFileName) {
  79. @strongify(self)
  80. [self.transitionAnimationView setAnimationNamed:audioVideoMatchingTransitionFileName inBundle:[NSBundle mainBundle]];
  81. [self.transitionAnimationView play];
  82. }];
  83. [[[[RACObserve(self.viewModel, userAvatar) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userAvatar) {
  84. @strongify(self)
  85. [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:userAvatar]];
  86. }];
  87. [[[[RACObserve(self.viewModel, matchingTypeIcon) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(UIImage * matchingTypeIcon) {
  88. @strongify(self)
  89. self.matchingTypeIcon.image = matchingTypeIcon;
  90. }];
  91. }
  92. - (LOTAnimationView *)transitionAnimationView{
  93. if (!_transitionAnimationView) {
  94. _transitionAnimationView = [[LOTAnimationView alloc]init];
  95. _transitionAnimationView.loopAnimation = YES;
  96. }
  97. return _transitionAnimationView;
  98. }
  99. - (UIView *)userAvatarAnimationView{
  100. if (!_userAvatarAnimationView) {
  101. _userAvatarAnimationView = [[UIView alloc]init];
  102. CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
  103. animation.keyPath = @"transform.scale";
  104. animation.values = @[@1.0,@1.1,@1.15,@1.2,@1.25,@1.3,@1.25,@1.2,@1.15,@1.1,@1.0];
  105. animation.duration = 2;
  106. animation.calculationMode = kCAAnimationCubic;
  107. animation.repeatCount = MAXFLOAT;
  108. [_userAvatarAnimationView.layer addAnimation:animation forKey:nil];
  109. }
  110. return _userAvatarAnimationView;
  111. }
  112. - (UIImageView *)userAvatarView{
  113. if (!_userAvatarView) {
  114. _userAvatarView = [[UIImageView alloc]init];
  115. _userAvatarView.contentMode = UIViewContentModeScaleAspectFill;
  116. _userAvatarView.backgroundColor = UIColor.lightGrayColor;
  117. _userAvatarView.layer.borderWidth = adapt(2);
  118. _userAvatarView.layer.borderColor = HexColorFromRGB(0xFFFFFF).CGColor;
  119. _userAvatarView.layer.cornerRadius = adapt(80)/2;
  120. _userAvatarView.layer.masksToBounds = YES;
  121. }
  122. return _userAvatarView;
  123. }
  124. - (UIImageView *)matchingTypeIcon{
  125. if (!_matchingTypeIcon) {
  126. _matchingTypeIcon = [[UIImageView alloc]init];
  127. }
  128. return _matchingTypeIcon;
  129. }
  130. - (UILabel *)transitionTipsLb{
  131. if (!_transitionTipsLb) {
  132. _transitionTipsLb = [[UILabel alloc]init];
  133. _transitionTipsLb.font = LCBoldFont(13);
  134. _transitionTipsLb.textColor = HexColorFromRGB(0xFFFFFF);
  135. _transitionTipsLb.textAlignment = NSTextAlignmentCenter;
  136. _transitionTipsLb.text = @"正在为您匹配有缘小姐姐,加速中~";
  137. }
  138. return _transitionTipsLb;
  139. }
  140. - (UILabel *)countdownLab{
  141. if(!_countdownLab){
  142. _countdownLab = [[UILabel alloc]init];
  143. _countdownLab.font = LCBoldFont(18);
  144. [_countdownLab setBackgroundColor:HexColorFromRGB(0xfd7bc5)];
  145. _countdownLab.textColor = [UIColor whiteColor];
  146. _countdownLab.textAlignment = NSTextAlignmentCenter;
  147. _countdownLab.text = @"正在进入速配";
  148. [_countdownLab setHidden:YES];
  149. }
  150. return _countdownLab;
  151. }
  152. @end