YMHomePageBannerView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. //
  2. // YMHomePageBannerView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/12.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMHomePageBannerView.h"
  9. #import "YMHomePageBannerOnTVCell.h"
  10. @interface YMHomePageBannerView()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  11. /// bannerVM
  12. @property (nonatomic, strong) YMHomePageBannerViewModel *viewModel;
  13. /// 顶部背景图
  14. @property (nonatomic, strong) UIImageView *topBgImgv;
  15. /// 顶部banner背景图
  16. @property (nonatomic, strong) UIImageView *bannerBgImgv;
  17. /// 视频速配视图
  18. @property (nonatomic, strong) UIImageView *videoMatchingView;
  19. /// 视频速配图标
  20. @property (nonatomic, strong) UIImageView *videoMatchingIcon;
  21. /// 视频速配标题标签
  22. @property (nonatomic, strong) UILabel *videoMatchingTitleLb;
  23. /// 视频速配详情标签
  24. @property (nonatomic, strong) UILabel *videoMatchingDetailLb;
  25. /// 语音速配视图
  26. @property (nonatomic, strong) UIImageView *voiceMatchingView;
  27. /// 语音速配图标
  28. @property (nonatomic, strong) UIImageView *voiceMatchingIcon;
  29. /// 语音速配标题标签
  30. @property (nonatomic, strong) UILabel *voiceMatchingTitleLb;
  31. /// 语音速配详情标签
  32. @property (nonatomic, strong) UILabel *voiceMatchingDetailLb;
  33. /// 上电视基础视图
  34. @property (nonatomic, strong) UIView *onTvBaseView;
  35. ///
  36. @property (nonatomic, strong) UIImageView *onTvImgView;
  37. /// 上电视视图
  38. @property (nonatomic, strong) TYCyclePagerView *onTvView;
  39. /// 如何上电视
  40. @property (nonatomic, strong) UIButton *onTvDescBtn;
  41. @end
  42. @implementation YMHomePageBannerView
  43. - (void)ym_setupViews{
  44. [self addSubview:self.topBgImgv];
  45. [self addSubview:self.bannerBgImgv];
  46. //[self addSubview:self.videoMatchingView];
  47. // [self.videoMatchingView addSubview:self.videoMatchingIcon];
  48. // [self.videoMatchingView addSubview:self.videoMatchingTitleLb];
  49. // [self.videoMatchingView addSubview:self.videoMatchingDetailLb];
  50. [self addSubview:self.onTvBaseView];
  51. [self.onTvBaseView addSubview:self.onTvImgView];
  52. self.onTvImgView.hidden = YES;
  53. [self.onTvBaseView addSubview:self.onTvView];
  54. [self.onTvBaseView addSubview:self.onTvDescBtn];
  55. // [self setNeedsUpdateConstraints];
  56. // [self updateConstraintsIfNeeded];
  57. [self steupConstraints];
  58. }
  59. - (void)steupConstraints {
  60. // NSArray *viewArr = @[self.videoMatchingView,self.voiceMatchingView];
  61. //
  62. // // 实现masonry水平固定控件宽度方法
  63. // // axisType 横排还是竖排
  64. // // fixedSpacing 两个控件间隔
  65. // // leadSpacing 第一个控件与边缘的间隔
  66. // // tailSpacing 最后一个控件与边缘的间隔
  67. // [viewArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:adapt(10) leadSpacing:adapt(20) tailSpacing:adapt(20)];
  68. //
  69. // // 设置array的垂直方向的约束
  70. // [viewArr mas_makeConstraints:^(MASConstraintMaker *make) {
  71. // make.top.equalTo(self).offset(adapt(10));
  72. // make.height.mas_equalTo(adapt(65));
  73. // }];
  74. [self.topBgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.top.left.bottom.right.equalTo(self);
  76. make.height.mas_equalTo(kYMStatusBarHeight + adapt(100));
  77. }];
  78. [self.bannerBgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.top.equalTo(self).offset( kYMStatusBarHeight + adapt(20));
  80. make.left.equalTo(self).offset(15);
  81. make.right.equalTo(self).offset(-15);
  82. make.height.mas_equalTo(adapt(70));
  83. }];
  84. // [self.bannerBgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  85. // make.left.equalTo(self).offset(15);
  86. // make.right.equalTo(self).offset(-3);
  87. // make.bottom.equalTo(self.bannerBgImgv.mas_bottom).offset(adapt(-10));
  88. // make.height.mas_equalTo(adapt(108));
  89. // }];
  90. // [self.videoMatchingView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. // make.top.equalTo(self.videoMatchingView);
  92. // make.left.equalTo(self).offset(adapt(20));
  93. // make.right.equalTo(self).offset(adapt(-20));
  94. // make.height.mas_equalTo(adapt(90));
  95. // }];
  96. // [self.videoMatchingIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  97. // make.top.equalTo(self.videoMatchingView);
  98. // make.right.equalTo(self.videoMatchingView);
  99. // make.bottom.equalTo(self.videoMatchingView);
  100. // make.width.mas_equalTo(adapt(105));
  101. // }];
  102. // [self.videoMatchingTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  103. // make.bottom.equalTo(self.videoMatchingView.mas_centerY).offset(adapt(-5));
  104. // make.left.equalTo(self.videoMatchingView).offset(adapt(15));
  105. // }];
  106. // [self.videoMatchingDetailLb mas_makeConstraints:^(MASConstraintMaker *make) {
  107. // make.top.equalTo(self.videoMatchingView.mas_centerY).offset(adapt(5));
  108. // make.left.equalTo(self.videoMatchingView).offset(adapt(15));
  109. // }];
  110. // [self.voiceMatchingIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  111. // make.top.equalTo(self.voiceMatchingView);
  112. // make.right.equalTo(self.voiceMatchingView);
  113. // make.bottom.equalTo(self.voiceMatchingView);
  114. // make.width.mas_equalTo(adapt(105));
  115. // }];
  116. //
  117. // [self.voiceMatchingTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  118. // make.bottom.equalTo(self.voiceMatchingView.mas_centerY).offset(adapt(-5));
  119. // make.left.equalTo(self.voiceMatchingView).offset(adapt(15));
  120. // }];
  121. //
  122. // [self.voiceMatchingDetailLb mas_makeConstraints:^(MASConstraintMaker *make) {
  123. // make.top.equalTo(self.voiceMatchingView.mas_centerY).offset(adapt(5));
  124. // make.left.equalTo(self.voiceMatchingView).offset(adapt(15));
  125. // }];
  126. // [self.onTvBaseView mas_makeConstraints:^(MASConstraintMaker *make) {
  127. // make.top.equalTo(self.videoMatchingView.mas_bottom).offset(adapt(15));
  128. // make.left.equalTo(self).offset(adapt(20));
  129. // make.right.equalTo(self).offset(adapt(-20));
  130. // make.bottom.equalTo(self).offset(adapt(-10));
  131. // make.height.mas_equalTo(adapt(56));
  132. // }];
  133. [self.onTvBaseView mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.top.equalTo(self.bannerBgImgv).offset(adapt(0));
  135. make.left.equalTo(self.bannerBgImgv).offset(adapt(20));
  136. make.right.equalTo(self.bannerBgImgv).offset(adapt(-10));
  137. make.bottom.equalTo(self.bannerBgImgv).offset(adapt(0));
  138. }];
  139. [self.onTvImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.top.left.right.bottom.equalTo(self.onTvBaseView);
  141. }];
  142. [self.onTvView mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.top.equalTo(self.onTvBaseView);
  144. make.left.equalTo(self.onTvBaseView);
  145. make.right.equalTo(self.onTvDescBtn.mas_left).offset(adapt(-10));
  146. make.bottom.equalTo(self.onTvBaseView);
  147. }];
  148. [self.onTvDescBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.centerY.equalTo(self.onTvBaseView.mas_centerY);
  150. make.right.equalTo(self.onTvBaseView).offset(adapt(-15));
  151. make.width.mas_equalTo(adapt(16));
  152. make.height.mas_equalTo(adapt(16));
  153. }];
  154. }
  155. - (void)ym_bindViewModel:(YMHomePageBannerViewModel*)viewModel{
  156. if (!viewModel) {
  157. return;
  158. }
  159. _viewModel = viewModel;
  160. @weakify(self)
  161. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  162. @strongify(self)
  163. [self.onTvView reloadData];
  164. [self.onTvView layoutIfNeeded];
  165. CGFloat matchingViewHeight = [self.videoMatchingView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  166. CGFloat onTvViewHeight = [self.onTvBaseView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  167. if (self.bannerViewHeightBlock) {
  168. CGFloat bannerHeight = kYMStatusBarHeight + adapt(100);
  169. self.bannerViewHeightBlock(bannerHeight);
  170. //self.bannerViewHeightBlock(adapt(10) + matchingViewHeight + adapt(15) + onTvViewHeight + adapt(10));
  171. }
  172. }];
  173. }
  174. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  175. return self.viewModel.onTvDataArray.count;
  176. }
  177. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  178. YMHomePageBannerOnTVCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMHomePageBannerOnTVCell class]) forIndex:index];
  179. [cell ym_bindViewModel:self.viewModel.onTvDataArray[index]];
  180. return cell;
  181. }
  182. /// banner样式
  183. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  184. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  185. layout.itemSize = CGSizeMake(pageView.bounds.size.width, pageView.bounds.size.height);
  186. layout.scrollDirection = TYCyclePagerScrollDirectionVertical;
  187. return layout;
  188. }
  189. /// pagerView当前展示
  190. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  191. }
  192. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{
  193. }
  194. - (void)pagerViewDidScroll:(TYCyclePagerView *)pageView{
  195. }
  196. /// pagerView将开始拖动
  197. - (void)pagerViewWillBeginDragging:(TYCyclePagerView *)pageView{
  198. }
  199. /// pagerView将开始减速
  200. - (void)pagerViewWillBeginDecelerating:(TYCyclePagerView *)pageView{
  201. }
  202. /// pagerView确认结束
  203. - (void)pagerViewDidEndDragging:(TYCyclePagerView *)pageView willDecelerate:(BOOL)decelerate{
  204. }
  205. /// pagerView确认减速
  206. - (void)pagerViewDidEndDecelerating:(TYCyclePagerView *)pageView{
  207. }
  208. /// pagerView将开始滚动动画
  209. - (void)pagerViewWillBeginScrollingAnimation:(TYCyclePagerView *)pageView{
  210. }
  211. /// pagerView确认结束滚动动画
  212. - (void)pagerViewDidEndScrollingAnimation:(TYCyclePagerView *)pageView{
  213. }
  214. - (UIImageView *)videoMatchingView{
  215. if (!_videoMatchingView) {
  216. _videoMatchingView = [[UIImageView alloc]init];
  217. _videoMatchingView.image = ImageByName(@"ym_home_page_temp_video_bg");
  218. _videoMatchingView.userInteractionEnabled = YES;
  219. // [_videoMatchingView.layer setCornerRadius:adapt(8)];
  220. // [_videoMatchingView.layer setMasksToBounds:YES];
  221. WS(weakSelf)
  222. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  223. [_videoMatchingView addGestureRecognizer:tap];
  224. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  225. [weakSelf.viewModel.gotoAudioVideoMatchingSubject sendNext:@(YMAudioVideoMatchingTypeVideo)];
  226. }];
  227. }
  228. return _videoMatchingView;
  229. }
  230. - (UIImageView *)topBgImgv {
  231. if (!_topBgImgv) {
  232. _topBgImgv = [[UIImageView alloc]init];
  233. _topBgImgv.hidden = YES;
  234. _topBgImgv.image = ImageByName(@"ym_home_page_top_bg");
  235. _topBgImgv.userInteractionEnabled = NO;
  236. // [_topBgImgv.layer setCornerRadius:adapt(8)];
  237. // [_topBgImgv.layer setMasksToBounds:YES];
  238. // WS(weakSelf)
  239. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  240. // [_topBgImgv addGestureRecognizer:tap];
  241. // [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  242. // [weakSelf.viewModel.gotoAudioVideoMatchingSubject sendNext:@(YMAudioVideoMatchingTypeVideo)];
  243. // }];
  244. }
  245. return _topBgImgv;
  246. }
  247. - (UIImageView *)bannerBgImgv {
  248. if (!_bannerBgImgv) {
  249. _bannerBgImgv = [[UIImageView alloc]init];
  250. _bannerBgImgv.image = ImageByName(@"ym_home_page_banner_bg");
  251. _bannerBgImgv.userInteractionEnabled = NO;
  252. }
  253. return _bannerBgImgv;
  254. }
  255. - (UIImageView *)videoMatchingIcon{
  256. if (!_videoMatchingIcon) {
  257. _videoMatchingIcon = [[UIImageView alloc]init];
  258. _videoMatchingIcon.image = ImageByName(@"ym_home_page_video_matching_icon");
  259. }
  260. return _videoMatchingIcon;
  261. }
  262. - (UILabel *)videoMatchingTitleLb{
  263. if (!_videoMatchingTitleLb) {
  264. _videoMatchingTitleLb = [[UILabel alloc]init];
  265. _videoMatchingTitleLb.font = LCBoldFont(17);
  266. _videoMatchingTitleLb.textColor = HexColorFromRGB(0xFFFFFF);
  267. _videoMatchingTitleLb.textAlignment = NSTextAlignmentLeft;
  268. _videoMatchingTitleLb.text = @"视频速配";
  269. }
  270. return _videoMatchingTitleLb;
  271. }
  272. - (UILabel *)videoMatchingDetailLb{
  273. if (!_videoMatchingDetailLb) {
  274. _videoMatchingDetailLb = [[UILabel alloc]init];
  275. _videoMatchingDetailLb.font = LCFont(12);
  276. _videoMatchingDetailLb.textColor = HexColorFromRGB(0xFFFFFF);
  277. _videoMatchingDetailLb.textAlignment = NSTextAlignmentLeft;
  278. _videoMatchingDetailLb.text = @"邂逅有缘人";
  279. }
  280. return _videoMatchingDetailLb;
  281. }
  282. - (UIImageView *)voiceMatchingView{
  283. if (!_voiceMatchingView) {
  284. _voiceMatchingView = [[UIImageView alloc]init];
  285. _voiceMatchingView.image = ImageByName(@"ym_home_page_voice_matching_bg");
  286. _voiceMatchingView.userInteractionEnabled = YES;
  287. WS(weakSelf)
  288. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  289. [_voiceMatchingView addGestureRecognizer:tap];
  290. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  291. [weakSelf.viewModel.gotoAudioVideoMatchingSubject sendNext:@(YMAudioVideoMatchingTypeAudio)];
  292. }];
  293. }
  294. return _voiceMatchingView;
  295. }
  296. - (UIImageView *)voiceMatchingIcon{
  297. if (!_voiceMatchingIcon) {
  298. _voiceMatchingIcon = [[UIImageView alloc]init];
  299. _voiceMatchingIcon.image = ImageByName(@"ym_home_page_voice_matching_icon");
  300. }
  301. return _voiceMatchingIcon;
  302. }
  303. - (UILabel *)voiceMatchingTitleLb{
  304. if (!_voiceMatchingTitleLb) {
  305. _voiceMatchingTitleLb = [[UILabel alloc]init];
  306. _voiceMatchingTitleLb.font = LCBoldFont(17);
  307. _voiceMatchingTitleLb.textColor = HexColorFromRGB(0xFFFFFF);
  308. _voiceMatchingTitleLb.textAlignment = NSTextAlignmentLeft;
  309. _voiceMatchingTitleLb.text = @"语音速配";
  310. }
  311. return _voiceMatchingTitleLb;
  312. }
  313. - (UILabel *)voiceMatchingDetailLb{
  314. if (!_voiceMatchingDetailLb) {
  315. _voiceMatchingDetailLb = [[UILabel alloc]init];
  316. _voiceMatchingDetailLb.font = LCFont(12);
  317. _voiceMatchingDetailLb.textColor = HexColorFromRGB(0xFFFFFF);
  318. _voiceMatchingDetailLb.textAlignment = NSTextAlignmentLeft;
  319. _voiceMatchingDetailLb.text = @"实时语音聊天";
  320. }
  321. return _voiceMatchingDetailLb;
  322. }
  323. - (UIView *)onTvBaseView{
  324. if (!_onTvBaseView) {
  325. _onTvBaseView = [[UIView alloc]init];
  326. // [_onTvBaseView ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  327. // [_onTvBaseView addRectCorner:UIRectCornerAllCorners radius:65/2];
  328. }
  329. return _onTvBaseView;
  330. }
  331. - (UIImageView *)onTvImgView{
  332. if (!_onTvImgView) {
  333. _onTvImgView = [[UIImageView alloc]init];
  334. _onTvImgView.image = ImageByName(@"home_tv_bg");
  335. _onTvImgView.userInteractionEnabled = YES;
  336. }
  337. return _onTvImgView;
  338. }
  339. - (TYCyclePagerView *)onTvView{
  340. if (!_onTvView) {
  341. _onTvView = [[TYCyclePagerView alloc]init];
  342. _onTvView.dataSource = self;
  343. _onTvView.delegate = self;
  344. //无限滚动
  345. _onTvView.isInfiniteLoop = YES;
  346. //自动轮播
  347. _onTvView.autoScrollInterval = 3.0f;
  348. [_onTvView registerClass:[YMHomePageBannerOnTVCell class] forCellWithReuseIdentifier:NSStringFromClass([YMHomePageBannerOnTVCell class])];
  349. _onTvView.userInteractionEnabled = NO;
  350. }
  351. return _onTvView;
  352. }
  353. - (UIButton *)onTvDescBtn{
  354. if (!_onTvDescBtn) {
  355. _onTvDescBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  356. // _onTvDescBtn.titleLabel.font = LCFont(11);
  357. // [_onTvDescBtn setTitle:@"如何上电视" forState:UIControlStateNormal];
  358. // [_onTvDescBtn setTitleColor:HexColorFromRGB(0x645E64) forState:UIControlStateNormal];
  359. [_onTvDescBtn setImage:ImageByName(@"home_tv_shuoming") forState:UIControlStateNormal];
  360. // _onTvDescBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  361. // [_onTvDescBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
  362. // CGFloat margin = 3;
  363. // _onTvDescBtn.imageEdgeInsets = UIEdgeInsetsMake(0, margin, 0, -margin);
  364. WS(weakSelf)
  365. [[[_onTvDescBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  366. [weakSelf.viewModel gotoOnTvVC];
  367. }];
  368. }
  369. return _onTvDescBtn;
  370. }
  371. @end