YMAuthenticationCenterView.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // YMAuthenticationCenterView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/2.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAuthenticationCenterView.h"
  9. #import "YMAuthenticationCenterViewModel.h"
  10. @interface YMAuthenticationCenterView ()
  11. /// 认证中心VM
  12. @property (nonatomic, strong) YMAuthenticationCenterViewModel *viewModel;
  13. /// 示例动作视图
  14. @property (nonatomic, strong) UIImageView *exampleActionView;
  15. /// 示例动作提示标签
  16. @property (nonatomic, strong) UILabel *exampleActionTipsLb;
  17. /// 本人动作视图
  18. @property (nonatomic, strong) UIImageView *myActionView;
  19. /// 本人动作提示标签
  20. @property (nonatomic, strong) UILabel *myActionTipsLb;
  21. /// 提示标签
  22. @property (nonatomic, strong) UILabel *tipsLb;
  23. /// 按钮视图
  24. @property (nonatomic, strong) UIView *buttonView;
  25. /// 立即上传按钮
  26. @property (nonatomic, strong) UIButton *uploadNowBtn;
  27. /// 重拍按钮
  28. @property (nonatomic, strong) UIButton *reshootBtn;
  29. @end
  30. @implementation YMAuthenticationCenterView
  31. - (void)ym_setupViews{
  32. [self addSubview:self.exampleActionView];
  33. [self addSubview:self.exampleActionTipsLb];
  34. [self addSubview:self.myActionView];
  35. [self addSubview:self.myActionTipsLb];
  36. [self addSubview:self.tipsLb];
  37. [self addSubview:self.buttonView];
  38. [self.buttonView addSubview:self.uploadNowBtn];
  39. [self.buttonView addSubview:self.reshootBtn];
  40. [self setNeedsUpdateConstraints];
  41. [self updateConstraintsIfNeeded];
  42. }
  43. - (void)updateConstraints {
  44. [self.exampleActionView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.equalTo(self).offset(adapt(12));
  46. make.left.equalTo(self).offset(adapt(12));
  47. make.width.height.mas_equalTo(adapt(172));
  48. }];
  49. [self.exampleActionTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerX.equalTo(self.exampleActionView.mas_centerX);
  51. make.top.equalTo(self.exampleActionView.mas_bottom).offset(adapt(12));
  52. }];
  53. [self.myActionView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self).offset(adapt(12));
  55. make.right.equalTo(self).offset(adapt(-12));
  56. make.width.height.mas_equalTo(adapt(172));
  57. }];
  58. [self.myActionTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.centerX.equalTo(self.myActionView.mas_centerX);
  60. make.top.equalTo(self.myActionView.mas_bottom).offset(adapt(12));
  61. }];
  62. [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.equalTo(self.exampleActionView.mas_bottom).offset(adapt(48));
  64. make.left.equalTo(self).offset(adapt(10));
  65. make.right.equalTo(self).offset(adapt(-10));
  66. }];
  67. [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(10));
  69. make.left.equalTo(self);
  70. make.right.equalTo(self);
  71. make.bottom.equalTo(self).offset(adapt(-10)).priorityHigh();
  72. make.height.mas_equalTo(adapt(100));
  73. }];
  74. NSArray *btnArr = @[self.uploadNowBtn,self.reshootBtn];
  75. // 实现masonry水平固定控件宽度方法
  76. // axisType 横排还是竖排
  77. // fixedSpacing 两个控件间隔
  78. // leadSpacing 第一个控件与边缘的间隔
  79. // tailSpacing 最后一个控件与边缘的间隔
  80. [btnArr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:adapt(10) leadSpacing:adapt(5) tailSpacing:adapt(5)];
  81. // 设置array的垂直方向的约束
  82. [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(self.buttonView).offset(adapt(12));
  84. make.right.equalTo(self.buttonView).offset(adapt(-12));
  85. }];
  86. [super updateConstraints];
  87. }
  88. - (void)ym_bindViewModel:(YMAuthenticationCenterViewModel *)viewModel{
  89. if (!viewModel) {
  90. return;
  91. }
  92. _viewModel = viewModel;
  93. @weakify(self)
  94. [[[[RACObserve(self.viewModel, samplePhotoUrl) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * samplePhotoUrl) {
  95. @strongify(self)
  96. [self.exampleActionView sd_setImageWithURL:[LCTools getImageUrlWithAddress:samplePhotoUrl] placeholderImage:[UIImage new] options:SDWebImageRefreshCached];
  97. }];
  98. [[[[RACObserve(self.viewModel, photo) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(UIImage * photo) {
  99. @strongify(self)
  100. self.myActionView.image = photo;
  101. }];
  102. }
  103. - (UIImageView *)exampleActionView{
  104. if (!_exampleActionView) {
  105. _exampleActionView = [[UIImageView alloc]init];
  106. _exampleActionView.contentMode = UIViewContentModeScaleAspectFill;
  107. _exampleActionView.backgroundColor = HexColorFromRGB(0xF6F6F6);
  108. _exampleActionView.layer.cornerRadius = adapt(10);
  109. _exampleActionView.layer.masksToBounds = YES;
  110. }
  111. return _exampleActionView;
  112. }
  113. - (UILabel *)exampleActionTipsLb{
  114. if (!_exampleActionTipsLb) {
  115. _exampleActionTipsLb = [[UILabel alloc]init];
  116. _exampleActionTipsLb.font = LCFont(14);
  117. _exampleActionTipsLb.textColor = HexColorFromRGB(0x1B2739);
  118. _exampleActionTipsLb.textAlignment = NSTextAlignmentCenter;
  119. _exampleActionTipsLb.text = @"示例动作";
  120. }
  121. return _exampleActionTipsLb;
  122. }
  123. - (UIImageView *)myActionView{
  124. if (!_myActionView) {
  125. _myActionView = [[UIImageView alloc]init];
  126. _myActionView.contentMode = UIViewContentModeScaleAspectFill;
  127. _myActionView.backgroundColor = HexColorFromRGB(0xF6F6F6);
  128. _myActionView.layer.cornerRadius = adapt(10);
  129. _myActionView.layer.masksToBounds = YES;
  130. }
  131. return _myActionView;
  132. }
  133. - (UILabel *)myActionTipsLb{
  134. if (!_myActionTipsLb) {
  135. _myActionTipsLb = [[UILabel alloc]init];
  136. _myActionTipsLb.font = LCFont(14);
  137. _myActionTipsLb.textColor = HexColorFromRGB(0x1B2739);
  138. _myActionTipsLb.textAlignment = NSTextAlignmentCenter;
  139. _myActionTipsLb.text = @"本人动作";
  140. }
  141. return _myActionTipsLb;
  142. }
  143. - (UILabel *)tipsLb{
  144. if (!_tipsLb) {
  145. _tipsLb = [[UILabel alloc]init];
  146. _tipsLb.font = LCFont(14);
  147. _tipsLb.textColor = HexColorFromRGB(0xFEC01A);
  148. _tipsLb.textAlignment = NSTextAlignmentCenter;
  149. _tipsLb.text = @"如未按示例动作拍照,将无法通过审核";
  150. _tipsLb.numberOfLines = 0;
  151. }
  152. return _tipsLb;
  153. }
  154. - (UIView *)buttonView{
  155. if (!_buttonView) {
  156. _buttonView = [[UIView alloc]init];
  157. }
  158. return _buttonView;
  159. }
  160. - (UIButton *)uploadNowBtn {
  161. if(!_uploadNowBtn){
  162. _uploadNowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  163. _uploadNowBtn.titleLabel.font = LCBoldFont(15);
  164. [_uploadNowBtn setTitle:@"立即上传" forState:UIControlStateNormal];
  165. [_uploadNowBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  166. [_uploadNowBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  167. _uploadNowBtn.layer.cornerRadius = adapt(10);
  168. WS(weakSelf)
  169. [[[_uploadNowBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  170. [weakSelf.viewModel uploadAuthenticationPhotoData];
  171. }];
  172. }
  173. return _uploadNowBtn;
  174. }
  175. - (UIButton *)reshootBtn {
  176. if(!_reshootBtn){
  177. _reshootBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  178. _reshootBtn.titleLabel.font = LCFont(13);
  179. [_reshootBtn setTitle:@"重拍" forState:UIControlStateNormal];
  180. [_reshootBtn setTitleColor:HexColorFromRGB(0x666666) forState:UIControlStateNormal];
  181. WS(weakSelf)
  182. [[[_reshootBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  183. [weakSelf.viewModel gotoCustomCamera];
  184. [weakSelf.viewModel.deleteAuditPhotoSubject sendNext:nil];
  185. weakSelf.myActionView.image = nil;
  186. }];
  187. }
  188. return _reshootBtn;
  189. }
  190. @end