123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- //
- // YMHomePageBannerView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/12.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMHomePageBannerView.h"
- #import "YMHomePageBannerOnTVCell.h"
- @interface YMHomePageBannerView()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
- /// bannerVM
- @property (nonatomic, strong) YMHomePageBannerViewModel *viewModel;
- /// 顶部背景图
- @property (nonatomic, strong) UIImageView *topBgImgv;
- /// 顶部banner背景图
- @property (nonatomic, strong) UIImageView *bannerBgImgv;
- /// 视频速配视图
- @property (nonatomic, strong) UIImageView *videoMatchingView;
- /// 视频速配图标
- @property (nonatomic, strong) UIImageView *videoMatchingIcon;
- /// 视频速配标题标签
- @property (nonatomic, strong) UILabel *videoMatchingTitleLb;
- /// 视频速配详情标签
- @property (nonatomic, strong) UILabel *videoMatchingDetailLb;
- /// 语音速配视图
- @property (nonatomic, strong) UIImageView *voiceMatchingView;
- /// 语音速配图标
- @property (nonatomic, strong) UIImageView *voiceMatchingIcon;
- /// 语音速配标题标签
- @property (nonatomic, strong) UILabel *voiceMatchingTitleLb;
- /// 语音速配详情标签
- @property (nonatomic, strong) UILabel *voiceMatchingDetailLb;
- /// 上电视基础视图
- @property (nonatomic, strong) UIView *onTvBaseView;
- ///
- @property (nonatomic, strong) UIImageView *onTvImgView;
- /// 上电视视图
- @property (nonatomic, strong) TYCyclePagerView *onTvView;
- /// 如何上电视
- @property (nonatomic, strong) UIButton *onTvDescBtn;
- @end
- @implementation YMHomePageBannerView
- - (void)ym_setupViews{
- [self addSubview:self.topBgImgv];
- [self addSubview:self.bannerBgImgv];
- //[self addSubview:self.videoMatchingView];
- // [self.videoMatchingView addSubview:self.videoMatchingIcon];
- // [self.videoMatchingView addSubview:self.videoMatchingTitleLb];
- // [self.videoMatchingView addSubview:self.videoMatchingDetailLb];
-
-
- [self addSubview:self.onTvBaseView];
- [self.onTvBaseView addSubview:self.onTvImgView];
- self.onTvImgView.hidden = YES;
- [self.onTvBaseView addSubview:self.onTvView];
- [self.onTvBaseView addSubview:self.onTvDescBtn];
- // [self setNeedsUpdateConstraints];
- // [self updateConstraintsIfNeeded];
-
- [self steupConstraints];
- }
- - (void)steupConstraints {
- // NSArray *viewArr = @[self.videoMatchingView,self.voiceMatchingView];
- //
- // // 实现masonry水平固定控件宽度方法
- // // axisType 横排还是竖排
- // // fixedSpacing 两个控件间隔
- // // leadSpacing 第一个控件与边缘的间隔
- // // tailSpacing 最后一个控件与边缘的间隔
- // [viewArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:adapt(10) leadSpacing:adapt(20) tailSpacing:adapt(20)];
- //
- // // 设置array的垂直方向的约束
- // [viewArr mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self).offset(adapt(10));
- // make.height.mas_equalTo(adapt(65));
- // }];
-
- [self.topBgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.right.equalTo(self);
- make.height.mas_equalTo(kYMStatusBarHeight + adapt(100));
- }];
-
- [self.bannerBgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset( kYMStatusBarHeight + adapt(20));
- make.left.equalTo(self).offset(15);
- make.right.equalTo(self).offset(-15);
- make.height.mas_equalTo(adapt(70));
- }];
- // [self.bannerBgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.equalTo(self).offset(15);
- // make.right.equalTo(self).offset(-3);
- // make.bottom.equalTo(self.bannerBgImgv.mas_bottom).offset(adapt(-10));
- // make.height.mas_equalTo(adapt(108));
- // }];
-
-
- // [self.videoMatchingView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.videoMatchingView);
- // make.left.equalTo(self).offset(adapt(20));
- // make.right.equalTo(self).offset(adapt(-20));
- // make.height.mas_equalTo(adapt(90));
- // }];
-
- // [self.videoMatchingIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.videoMatchingView);
- // make.right.equalTo(self.videoMatchingView);
- // make.bottom.equalTo(self.videoMatchingView);
- // make.width.mas_equalTo(adapt(105));
- // }];
-
- // [self.videoMatchingTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.bottom.equalTo(self.videoMatchingView.mas_centerY).offset(adapt(-5));
- // make.left.equalTo(self.videoMatchingView).offset(adapt(15));
- // }];
-
- // [self.videoMatchingDetailLb mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.videoMatchingView.mas_centerY).offset(adapt(5));
- // make.left.equalTo(self.videoMatchingView).offset(adapt(15));
- // }];
-
- // [self.voiceMatchingIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.voiceMatchingView);
- // make.right.equalTo(self.voiceMatchingView);
- // make.bottom.equalTo(self.voiceMatchingView);
- // make.width.mas_equalTo(adapt(105));
- // }];
- //
- // [self.voiceMatchingTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.bottom.equalTo(self.voiceMatchingView.mas_centerY).offset(adapt(-5));
- // make.left.equalTo(self.voiceMatchingView).offset(adapt(15));
- // }];
- //
- // [self.voiceMatchingDetailLb mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.voiceMatchingView.mas_centerY).offset(adapt(5));
- // make.left.equalTo(self.voiceMatchingView).offset(adapt(15));
- // }];
-
- // [self.onTvBaseView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.videoMatchingView.mas_bottom).offset(adapt(15));
- // make.left.equalTo(self).offset(adapt(20));
- // make.right.equalTo(self).offset(adapt(-20));
- // make.bottom.equalTo(self).offset(adapt(-10));
- // make.height.mas_equalTo(adapt(56));
- // }];
- [self.onTvBaseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bannerBgImgv).offset(adapt(0));
- make.left.equalTo(self.bannerBgImgv).offset(adapt(20));
- make.right.equalTo(self.bannerBgImgv).offset(adapt(-10));
- make.bottom.equalTo(self.bannerBgImgv).offset(adapt(0));
- }];
-
- [self.onTvImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.equalTo(self.onTvBaseView);
- }];
-
- [self.onTvView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.onTvBaseView);
- make.left.equalTo(self.onTvBaseView);
- make.right.equalTo(self.onTvDescBtn.mas_left).offset(adapt(-10));
- make.bottom.equalTo(self.onTvBaseView);
- }];
-
- [self.onTvDescBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.onTvBaseView.mas_centerY);
- make.right.equalTo(self.onTvBaseView).offset(adapt(-15));
- make.width.mas_equalTo(adapt(16));
- make.height.mas_equalTo(adapt(16));
- }];
- }
- - (void)ym_bindViewModel:(YMHomePageBannerViewModel*)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
-
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.onTvView reloadData];
- [self.onTvView layoutIfNeeded];
-
- CGFloat matchingViewHeight = [self.videoMatchingView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
- CGFloat onTvViewHeight = [self.onTvBaseView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
- if (self.bannerViewHeightBlock) {
- CGFloat bannerHeight = kYMStatusBarHeight + adapt(100);
- self.bannerViewHeightBlock(bannerHeight);
- //self.bannerViewHeightBlock(adapt(10) + matchingViewHeight + adapt(15) + onTvViewHeight + adapt(10));
- }
- }];
-
- }
- - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
- return self.viewModel.onTvDataArray.count;
- }
- - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
- YMHomePageBannerOnTVCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMHomePageBannerOnTVCell class]) forIndex:index];
- [cell ym_bindViewModel:self.viewModel.onTvDataArray[index]];
- return cell;
- }
- /// banner样式
- - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
- TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
- layout.itemSize = CGSizeMake(pageView.bounds.size.width, pageView.bounds.size.height);
- layout.scrollDirection = TYCyclePagerScrollDirectionVertical;
- return layout;
- }
- /// pagerView当前展示
- - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
-
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{
-
- }
- - (void)pagerViewDidScroll:(TYCyclePagerView *)pageView{
- }
- /// pagerView将开始拖动
- - (void)pagerViewWillBeginDragging:(TYCyclePagerView *)pageView{
- }
- /// pagerView将开始减速
- - (void)pagerViewWillBeginDecelerating:(TYCyclePagerView *)pageView{
- }
- /// pagerView确认结束
- - (void)pagerViewDidEndDragging:(TYCyclePagerView *)pageView willDecelerate:(BOOL)decelerate{
- }
- /// pagerView确认减速
- - (void)pagerViewDidEndDecelerating:(TYCyclePagerView *)pageView{
- }
- /// pagerView将开始滚动动画
- - (void)pagerViewWillBeginScrollingAnimation:(TYCyclePagerView *)pageView{
- }
- /// pagerView确认结束滚动动画
- - (void)pagerViewDidEndScrollingAnimation:(TYCyclePagerView *)pageView{
- }
- - (UIImageView *)videoMatchingView{
- if (!_videoMatchingView) {
- _videoMatchingView = [[UIImageView alloc]init];
- _videoMatchingView.image = ImageByName(@"ym_home_page_temp_video_bg");
- _videoMatchingView.userInteractionEnabled = YES;
- // [_videoMatchingView.layer setCornerRadius:adapt(8)];
- // [_videoMatchingView.layer setMasksToBounds:YES];
- WS(weakSelf)
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
- [_videoMatchingView addGestureRecognizer:tap];
- [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf.viewModel.gotoAudioVideoMatchingSubject sendNext:@(YMAudioVideoMatchingTypeVideo)];
- }];
- }
- return _videoMatchingView;
- }
- - (UIImageView *)topBgImgv {
- if (!_topBgImgv) {
- _topBgImgv = [[UIImageView alloc]init];
- _topBgImgv.hidden = YES;
- _topBgImgv.image = ImageByName(@"ym_home_page_top_bg");
- _topBgImgv.userInteractionEnabled = NO;
- // [_topBgImgv.layer setCornerRadius:adapt(8)];
- // [_topBgImgv.layer setMasksToBounds:YES];
- // WS(weakSelf)
- // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
- // [_topBgImgv addGestureRecognizer:tap];
- // [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- // [weakSelf.viewModel.gotoAudioVideoMatchingSubject sendNext:@(YMAudioVideoMatchingTypeVideo)];
- // }];
- }
- return _topBgImgv;
- }
- - (UIImageView *)bannerBgImgv {
- if (!_bannerBgImgv) {
- _bannerBgImgv = [[UIImageView alloc]init];
- _bannerBgImgv.image = ImageByName(@"ym_home_page_banner_bg");
- _bannerBgImgv.userInteractionEnabled = NO;
- }
- return _bannerBgImgv;
- }
- - (UIImageView *)videoMatchingIcon{
- if (!_videoMatchingIcon) {
- _videoMatchingIcon = [[UIImageView alloc]init];
- _videoMatchingIcon.image = ImageByName(@"ym_home_page_video_matching_icon");
- }
- return _videoMatchingIcon;
- }
- - (UILabel *)videoMatchingTitleLb{
- if (!_videoMatchingTitleLb) {
- _videoMatchingTitleLb = [[UILabel alloc]init];
- _videoMatchingTitleLb.font = LCBoldFont(17);
- _videoMatchingTitleLb.textColor = HexColorFromRGB(0xFFFFFF);
- _videoMatchingTitleLb.textAlignment = NSTextAlignmentLeft;
- _videoMatchingTitleLb.text = @"视频速配";
- }
- return _videoMatchingTitleLb;
- }
- - (UILabel *)videoMatchingDetailLb{
- if (!_videoMatchingDetailLb) {
- _videoMatchingDetailLb = [[UILabel alloc]init];
- _videoMatchingDetailLb.font = LCFont(12);
- _videoMatchingDetailLb.textColor = HexColorFromRGB(0xFFFFFF);
- _videoMatchingDetailLb.textAlignment = NSTextAlignmentLeft;
- _videoMatchingDetailLb.text = @"邂逅有缘人";
- }
- return _videoMatchingDetailLb;
- }
- - (UIImageView *)voiceMatchingView{
- if (!_voiceMatchingView) {
- _voiceMatchingView = [[UIImageView alloc]init];
- _voiceMatchingView.image = ImageByName(@"ym_home_page_voice_matching_bg");
- _voiceMatchingView.userInteractionEnabled = YES;
- WS(weakSelf)
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
- [_voiceMatchingView addGestureRecognizer:tap];
- [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf.viewModel.gotoAudioVideoMatchingSubject sendNext:@(YMAudioVideoMatchingTypeAudio)];
- }];
- }
- return _voiceMatchingView;
- }
- - (UIImageView *)voiceMatchingIcon{
- if (!_voiceMatchingIcon) {
- _voiceMatchingIcon = [[UIImageView alloc]init];
- _voiceMatchingIcon.image = ImageByName(@"ym_home_page_voice_matching_icon");
- }
- return _voiceMatchingIcon;
- }
- - (UILabel *)voiceMatchingTitleLb{
- if (!_voiceMatchingTitleLb) {
- _voiceMatchingTitleLb = [[UILabel alloc]init];
- _voiceMatchingTitleLb.font = LCBoldFont(17);
- _voiceMatchingTitleLb.textColor = HexColorFromRGB(0xFFFFFF);
- _voiceMatchingTitleLb.textAlignment = NSTextAlignmentLeft;
- _voiceMatchingTitleLb.text = @"语音速配";
- }
- return _voiceMatchingTitleLb;
- }
- - (UILabel *)voiceMatchingDetailLb{
- if (!_voiceMatchingDetailLb) {
- _voiceMatchingDetailLb = [[UILabel alloc]init];
- _voiceMatchingDetailLb.font = LCFont(12);
- _voiceMatchingDetailLb.textColor = HexColorFromRGB(0xFFFFFF);
- _voiceMatchingDetailLb.textAlignment = NSTextAlignmentLeft;
- _voiceMatchingDetailLb.text = @"实时语音聊天";
- }
- return _voiceMatchingDetailLb;
- }
- - (UIView *)onTvBaseView{
- if (!_onTvBaseView) {
- _onTvBaseView = [[UIView alloc]init];
- // [_onTvBaseView ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
- // [_onTvBaseView addRectCorner:UIRectCornerAllCorners radius:65/2];
- }
- return _onTvBaseView;
- }
- - (UIImageView *)onTvImgView{
- if (!_onTvImgView) {
- _onTvImgView = [[UIImageView alloc]init];
- _onTvImgView.image = ImageByName(@"home_tv_bg");
- _onTvImgView.userInteractionEnabled = YES;
- }
- return _onTvImgView;
- }
- - (TYCyclePagerView *)onTvView{
- if (!_onTvView) {
- _onTvView = [[TYCyclePagerView alloc]init];
- _onTvView.dataSource = self;
- _onTvView.delegate = self;
- //无限滚动
- _onTvView.isInfiniteLoop = YES;
- //自动轮播
- _onTvView.autoScrollInterval = 3.0f;
- [_onTvView registerClass:[YMHomePageBannerOnTVCell class] forCellWithReuseIdentifier:NSStringFromClass([YMHomePageBannerOnTVCell class])];
- _onTvView.userInteractionEnabled = NO;
-
- }
- return _onTvView;
- }
- - (UIButton *)onTvDescBtn{
- if (!_onTvDescBtn) {
- _onTvDescBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- // _onTvDescBtn.titleLabel.font = LCFont(11);
- // [_onTvDescBtn setTitle:@"如何上电视" forState:UIControlStateNormal];
- // [_onTvDescBtn setTitleColor:HexColorFromRGB(0x645E64) forState:UIControlStateNormal];
- [_onTvDescBtn setImage:ImageByName(@"home_tv_shuoming") forState:UIControlStateNormal];
- // _onTvDescBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- // [_onTvDescBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
- // CGFloat margin = 3;
- // _onTvDescBtn.imageEdgeInsets = UIEdgeInsetsMake(0, margin, 0, -margin);
- WS(weakSelf)
- [[[_onTvDescBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- [weakSelf.viewModel gotoOnTvVC];
-
- }];
- }
- return _onTvDescBtn;
- }
- @end
|