YMEditProfileViewController.m 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //
  2. // YMEditProfileViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/18.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMEditProfileViewController.h"
  9. #import "YMEditProfileViewModel.h"
  10. #import "YMEditProfileAvatarView.h"
  11. #import "YMEditProfileAlbumView.h"
  12. #import "YMEditProfileVoiceView.h"
  13. #import "YMEditProfileInfoView.h"
  14. #import "YMEditProfileIntroView.h"
  15. #import "YMEditProfileTagView.h"
  16. @interface YMEditProfileViewController ()
  17. /// 编辑资料VM
  18. @property (nonatomic, strong) YMEditProfileViewModel *viewModel;
  19. /// 保存按钮
  20. @property (nonatomic, strong) UIButton *saveBtn;
  21. /// 容器滚动视图
  22. @property (nonatomic, strong) UIScrollView *contentScrollView;
  23. /// 容器视图
  24. @property (nonatomic, strong) UIView *contentView;
  25. /// 头像视图
  26. @property (nonatomic, strong) YMEditProfileAvatarView *avatarView;
  27. /// 相册视图
  28. @property (nonatomic, strong) YMEditProfileAlbumView *albumView;
  29. /// 语音视图
  30. @property (nonatomic, strong) YMEditProfileVoiceView *voiceView;
  31. /// 信息视图
  32. @property (nonatomic, strong) YMEditProfileInfoView *infoView;
  33. /// 介绍视图
  34. @property (nonatomic, strong) YMEditProfileIntroView *introView;
  35. /// 标签视图
  36. @property (nonatomic, strong) YMEditProfileTagView *tagView;
  37. @end
  38. @implementation YMEditProfileViewController
  39. @dynamic viewModel;
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.ym_customNavView.backgroundColor = UIColor.clearColor;
  43. UIImageView *topBgImgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ym_messages_top_bg"]];
  44. topBgImgv.frame = CGRectMake(0, 0, kScreenWidth, StatusBarHeight + adapt(54));
  45. [self.view addSubview:topBgImgv];
  46. }
  47. - (void)ym_setupViews{
  48. //[self setRightBarButtonWithCustomView:self.saveBtn];
  49. [self.view addSubview:self.contentScrollView];
  50. [self.view sendSubviewToBack:self.contentScrollView];
  51. [self.contentScrollView addSubview:self.contentView];
  52. [self.contentView addSubview:self.avatarView];
  53. [self.contentView addSubview:self.albumView];
  54. [self.contentView addSubview:self.voiceView];
  55. [self.contentView addSubview:self.infoView];
  56. [self.contentView addSubview:self.introView];
  57. [self.contentView addSubview:self.tagView];
  58. [self.view addSubview:self.saveBtn];
  59. [self.view setNeedsUpdateConstraints];
  60. [self.view updateConstraintsIfNeeded];
  61. }
  62. - (void)updateViewConstraints{
  63. [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(self.view).offset(kYMNavHeight);
  65. make.left.equalTo(self.view);
  66. make.right.equalTo(self.view);
  67. make.bottom.equalTo(self.view);
  68. }];
  69. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.edges.equalTo(self.contentScrollView);
  71. make.width.equalTo(self.contentScrollView.mas_width);
  72. }];
  73. [self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.equalTo(self.contentView).offset(adapt(15));
  75. make.left.equalTo(self.contentView).offset(adapt(15));
  76. make.right.equalTo(self.contentView).offset(adapt(-15));
  77. }];
  78. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.top.equalTo(self.avatarView.mas_bottom).offset(adapt(10));
  80. make.left.equalTo(self.avatarView.mas_left);
  81. make.right.equalTo(self.avatarView.mas_right);
  82. }];
  83. [self.voiceView mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.top.equalTo(self.albumView.mas_bottom).offset(adapt(10));
  85. make.left.equalTo(self.avatarView.mas_left);
  86. make.right.equalTo(self.avatarView.mas_right);
  87. }];
  88. [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.top.equalTo(self.voiceView.mas_bottom).offset(adapt(10));
  90. make.left.equalTo(self.avatarView.mas_left);
  91. make.right.equalTo(self.avatarView.mas_right);
  92. }];
  93. [self.introView mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.top.equalTo(self.infoView.mas_bottom);
  95. make.left.equalTo(self.avatarView.mas_left);
  96. make.right.equalTo(self.avatarView.mas_right);
  97. }];
  98. [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.top.equalTo(self.introView.mas_bottom);
  100. make.left.equalTo(self.avatarView.mas_left);
  101. make.right.equalTo(self.avatarView.mas_right);
  102. make.bottom.equalTo(self.contentView).offset(adapt(-100));
  103. }];
  104. [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.left.equalTo(self.view).offset(adapt(32));
  106. make.right.equalTo(self.view).offset(adapt(-32));
  107. make.bottom.equalTo(self.view).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  108. make.height.mas_equalTo(adapt(50));
  109. }];
  110. [super updateViewConstraints];
  111. }
  112. - (void)ym_bindViewModel{
  113. [self.avatarView ym_bindViewModel:self.viewModel];
  114. [self.albumView ym_bindViewModel:self.viewModel];
  115. [self.voiceView ym_bindViewModel:self.viewModel];
  116. [self.infoView ym_bindViewModel:self.viewModel];
  117. [self.introView ym_bindViewModel:self.viewModel];
  118. [self.tagView ym_bindViewModel:self.viewModel];
  119. [self.viewModel getEditProfileInfoData];
  120. }
  121. - (UIButton *)saveBtn{
  122. if (!_saveBtn) {
  123. _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  124. _saveBtn.titleLabel.font = LCBoldFont(18);
  125. [_saveBtn setTitle:@"保存" forState:UIControlStateNormal];
  126. [_saveBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  127. [_saveBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  128. _saveBtn.layer.cornerRadius = adapt(12);
  129. _saveBtn.layer.masksToBounds = YES;
  130. WS(weakSelf)
  131. [[[_saveBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  132. [weakSelf.viewModel uploadAlbumData];
  133. }];
  134. }
  135. return _saveBtn;
  136. }
  137. - (UIScrollView *)contentScrollView{
  138. if (!_contentScrollView) {
  139. _contentScrollView = [[UIScrollView alloc] init];
  140. _contentScrollView.alwaysBounceVertical = YES;
  141. _contentScrollView.showsVerticalScrollIndicator = NO;
  142. _contentScrollView.showsHorizontalScrollIndicator = NO;
  143. _contentScrollView.backgroundColor = UIColor.clearColor; //HexColorFromRGB(0xF8F8F8);
  144. _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  145. }
  146. return _contentScrollView;
  147. }
  148. - (UIView *)contentView{
  149. if (!_contentView) {
  150. _contentView = [[UIView alloc]init];
  151. }
  152. return _contentView;
  153. }
  154. - (YMEditProfileAvatarView *)avatarView{
  155. if (!_avatarView) {
  156. _avatarView = [[YMEditProfileAvatarView alloc]init];
  157. _avatarView.backgroundColor = UIColor.whiteColor;
  158. [_avatarView addRectCorner:UIRectCornerAllCorners radius:adapt(10)];
  159. _avatarView.userInteractionEnabled = YES;
  160. WS(weakSelf)
  161. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  162. [_avatarView addGestureRecognizer:tap];
  163. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  164. [weakSelf.viewModel openAvatarPickerPopupView];
  165. }];
  166. }
  167. return _avatarView;
  168. }
  169. - (YMEditProfileAlbumView *)albumView{
  170. if (!_albumView) {
  171. _albumView = [[YMEditProfileAlbumView alloc]init];
  172. _albumView.backgroundColor = UIColor.whiteColor;
  173. [_albumView addRectCorner:UIRectCornerAllCorners radius:adapt(10)];
  174. }
  175. return _albumView;
  176. }
  177. - (YMEditProfileVoiceView *)voiceView{
  178. if (!_voiceView) {
  179. _voiceView = [[YMEditProfileVoiceView alloc]init];
  180. _voiceView.backgroundColor = UIColor.whiteColor;
  181. [_voiceView addRectCorner:UIRectCornerAllCorners radius:adapt(10)];
  182. _voiceView.userInteractionEnabled = YES;
  183. WS(weakSelf)
  184. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  185. [_voiceView addGestureRecognizer:tap];
  186. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  187. [weakSelf.viewModel gotoSoundShowcase];
  188. }];
  189. }
  190. return _voiceView;
  191. }
  192. - (YMEditProfileInfoView *)infoView{
  193. if (!_infoView) {
  194. _infoView = [[YMEditProfileInfoView alloc]init];
  195. _infoView.backgroundColor = UIColor.whiteColor;
  196. [_infoView addRectCorner:UIRectCornerTopLeft|UIRectCornerTopRight radius:adapt(10)];
  197. }
  198. return _infoView;
  199. }
  200. - (YMEditProfileIntroView *)introView{
  201. if (!_introView) {
  202. _introView = [[YMEditProfileIntroView alloc]init];
  203. _introView.backgroundColor = UIColor.whiteColor;
  204. _introView.userInteractionEnabled = YES;
  205. WS(weakSelf)
  206. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  207. [_introView addGestureRecognizer:tap];
  208. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  209. [weakSelf.viewModel.editProfileOperationSubject sendNext:@(YMEditProfileTypeIntro)];
  210. }];
  211. }
  212. return _introView;
  213. }
  214. - (YMEditProfileTagView *)tagView{
  215. if (!_tagView) {
  216. _tagView = [[YMEditProfileTagView alloc]init];
  217. _tagView.backgroundColor = UIColor.whiteColor;
  218. [_tagView addRectCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight radius:adapt(10)];
  219. _tagView.userInteractionEnabled = YES;
  220. WS(weakSelf)
  221. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  222. [_tagView addGestureRecognizer:tap];
  223. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  224. [weakSelf.viewModel.editProfileOperationSubject sendNext:@(YMEditProfileTypeTag)];
  225. }];
  226. }
  227. return _tagView;
  228. }
  229. @end