// // YMInvitingPrizesViewController.m // MSYOUPAI // // Created by YoMi on 2024/3/5. // Copyright © 2024 MS. All rights reserved. // #import "YMInvitingPrizesViewController.h" #import "YMInvitingPrizesViewModel.h" #import "YMInvitingPrizesMyInvitationView.h" #import "YMInvitingPrizesIncentivesNotesView.h" #import "YMInvitingPrizesSharePosterPopupView.h" @interface YMInvitingPrizesViewController () /// 邀请有奖VM @property (nonatomic, strong) YMInvitingPrizesViewModel *viewModel; /// 容器滚动视图 @property (nonatomic, strong) UIScrollView *contentScrollView; /// 容器视图 @property (nonatomic, strong) UIView *contentView; /// 邀请背景视图 @property (nonatomic, strong) UIImageView *invitationBgView; /// 立即邀请按钮 @property (nonatomic, strong) UIButton *invitationNowBtn; /// 我的邀请视图 @property (nonatomic, strong) YMInvitingPrizesMyInvitationView *myInvitationView; /// 奖励说明视图 @property (nonatomic, strong) YMInvitingPrizesIncentivesNotesView *incentivesNotesView; /// @property (nonatomic, strong) UIImageView *hingeImgv; @end @implementation YMInvitingPrizesViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; self.ym_navigationStyle = YMBaseNavigationStyleClearBgBlackBackArrow; self.title = @"邀请有礼"; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; } - (void)ym_setupViews{ [self.view addSubview:self.contentScrollView]; [self.view sendSubviewToBack:self.contentScrollView]; [self.contentScrollView addSubview:self.contentView]; [self.contentView addSubview:self.invitationBgView]; [self.invitationBgView addSubview:self.invitationNowBtn]; [self.contentView addSubview:self.myInvitationView]; [self.contentView addSubview:self.incentivesNotesView]; [self.contentView addSubview:self.hingeImgv]; self.contentView.backgroundColor = rgba(255, 82, 112, 1); [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints{ [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view); make.left.equalTo(self.view); make.right.equalTo(self.view); make.bottom.equalTo(self.view); }]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentScrollView); make.width.equalTo(self.contentScrollView.mas_width); }]; [self.invitationBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView); make.left.equalTo(self.contentView); make.right.equalTo(self.contentView); make.height.mas_equalTo(adapt(666)); }]; // UIImageView *bgv = [[UIImageView alloc] init]; // bgv.image = ImageByName(@"ym_inviting_prizes_bg"); // bgv.layer.zPosition = -1; // [self.contentView insertSubview:bgv atIndex:0]; // // [bgv mas_updateConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.invitationBgView.mas_bottom).offset(adapt(-60)); // make.bottom.equalTo(self.contentView).offset(adapt(-0)); // make.left.right.equalTo(self.contentView); // }]; [self.invitationNowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.invitationBgView.mas_centerX); make.centerY.equalTo(self.invitationBgView.mas_bottom).offset(adapt(-250)); make.width.mas_equalTo(adapt(289)); make.height.mas_equalTo(adapt(75)); }]; [self.myInvitationView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.invitationNowBtn.mas_bottom).offset(adapt(13)); make.left.equalTo(self.contentView); make.right.equalTo(self.contentView); }]; [self.incentivesNotesView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myInvitationView.mas_bottom).offset(adapt(12)); make.left.equalTo(self.contentView); make.right.equalTo(self.contentView); make.bottom.equalTo(self.contentView).offset(adapt(-56)); }]; [self.hingeImgv mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myInvitationView.mas_bottom).offset(adapt(-26)); make.left.equalTo(self.contentView).offset(adapt(40)); make.right.equalTo(self.contentView).offset(adapt(-40)); make.height.mas_equalTo(adapt(66)); }]; //CGRect rect = CGRectMake(0, 0, self.contentScrollView.contentSize.height, self.contentScrollView.contentSize.height); UIView *gradientView = [[UIView alloc] initWithFrame:CGRectZero]; [gradientView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xFCE3C4), HexColorFromRGB(0xF7891B)] locations:@[@(0),@(1)] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(0, 1)]; [self.contentScrollView insertSubview:gradientView atIndex:0]; [gradientView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.invitationBgView.mas_bottom).offset(adapt(-23)); make.left.right.bottom.equalTo(self.contentScrollView); }]; [super updateViewConstraints]; } - (void)ym_bindViewModel{ [self.myInvitationView ym_bindViewModel:self.viewModel]; [self.incentivesNotesView ym_bindViewModel:self.viewModel]; [self.viewModel getInvitingPrizesInfoData]; } - (void)openSharePosterPopupView{ YMInvitingPrizesSharePosterPopupView *customView = [[YMInvitingPrizesSharePosterPopupView alloc]init]; [customView ym_bindViewModel:self.viewModel]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; popupView.popDuration = 0.3; [popupView pop]; @weakify(popupView) customView.dismissBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; } - (UIScrollView *)contentScrollView{ if (!_contentScrollView) { _contentScrollView = [[UIScrollView alloc]init]; _contentScrollView.bounces = NO; _contentScrollView.alwaysBounceVertical = YES; _contentScrollView.showsVerticalScrollIndicator = NO; _contentScrollView.showsHorizontalScrollIndicator = NO; _contentScrollView.backgroundColor = UIColor.clearColor; _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; } return _contentScrollView; } - (UIView *)contentView{ if (!_contentView) { _contentView = [[UIView alloc]init]; } return _contentView; } - (UIImageView *)invitationBgView{ if (!_invitationBgView) { _invitationBgView = [[UIImageView alloc]init]; _invitationBgView.contentMode = UIViewContentModeScaleAspectFill; _invitationBgView.image = ImageByName(@"ym_inviting_prizes_invitation_bg"); _invitationBgView.userInteractionEnabled = YES; UILabel * titleL = [UILabel new]; titleL.text=@"邀请好友的奖励"; titleL.textColor=UIColor.whiteColor; titleL.font=LCBoldFont(44); titleL.textAlignment=NSTextAlignmentCenter; [_invitationBgView addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(_invitationBgView); make.top.equalTo(_invitationBgView.top).offset(100); }]; UIButton * remarkL = [UIButton new]; [_invitationBgView addSubview:remarkL]; [remarkL setBackgroundImage:ImageByName(@"ym_inviting_prizes_remark_bar") forState:UIControlStateNormal]; [remarkL setTitle:@"— 超多福利拿到手软 —" forState:0]; [remarkL setTitleColor:rgba(235, 75, 75, 1) forState:0]; remarkL.titleLabel.font = LCBoldFont(16); [remarkL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(_invitationBgView); make.top.equalTo(titleL.bottom).offset(10); make.size.equalTo(CGSizeMake(226, 34)); }]; } return _invitationBgView; } - (UIButton *)invitationNowBtn{ if (!_invitationNowBtn) { _invitationNowBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_invitationNowBtn setBackgroundImage:ImageByName(@"ym_inviting_prizes_invitation_now") forState:UIControlStateNormal]; [_invitationNowBtn setTitle:@"立即邀请好友" forState:0]; [_invitationNowBtn setTitleColor:[UIColor whiteColor] forState:0]; _invitationNowBtn.titleLabel.font = LCBoldFont(26); WS(weakSelf) [[[_invitationNowBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf openSharePosterPopupView]; }]; } return _invitationNowBtn; } - (YMInvitingPrizesMyInvitationView *)myInvitationView{ if (!_myInvitationView) { _myInvitationView = [[YMInvitingPrizesMyInvitationView alloc]init]; } return _myInvitationView; } - (YMInvitingPrizesIncentivesNotesView *)incentivesNotesView{ if (!_incentivesNotesView) { _incentivesNotesView = [[YMInvitingPrizesIncentivesNotesView alloc]init]; } return _incentivesNotesView; } - (UIImageView *)hingeImgv { if (!_hingeImgv) { _hingeImgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ym_inviting_prizes_lian_jie"]]; _hingeImgv.contentMode = UIViewContentModeScaleToFill; _hingeImgv.layer.zPosition = 1; _hingeImgv.hidden = YES; } return _hingeImgv; } @end