diff --git a/keyBoard/Class/Pay/VC/KBPayMainVC.m b/keyBoard/Class/Pay/VC/KBPayMainVC.m index 365f35e..ff70ad7 100644 --- a/keyBoard/Class/Pay/VC/KBPayMainVC.m +++ b/keyBoard/Class/Pay/VC/KBPayMainVC.m @@ -45,6 +45,12 @@ static const CGFloat JXheightForHeaderInSection = 39; @property (nonatomic, strong) UIButton *closeButton; // 当前选中的方案索引 @property (nonatomic, strong) UIButton *restoreButton; +/// 底部固定区域 +@property (nonatomic, strong) UIView *bottomContainer; +@property (nonatomic, strong) UIButton *payButton; +@property (nonatomic, strong) UILabel *agreementLabel; +@property (nonatomic, strong) UIButton *agreementButton; + @end @implementation KBPayMainVC @@ -138,7 +144,34 @@ static const CGFloat JXheightForHeaderInSection = 39; self.pagerView.mainTableView.backgroundColor = [UIColor colorWithHex:0xF6F7FB]; - + + // 底部固定区域 + [self.view addSubview:self.bottomContainer]; + [self.bottomContainer addSubview:self.payButton]; + [self.bottomContainer addSubview:self.agreementLabel]; + [self.bottomContainer addSubview:self.agreementButton]; + + [self.bottomContainer mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.right.bottom.equalTo(self.view); + }]; + + [self.agreementButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerX.equalTo(self.bottomContainer); + make.bottom.equalTo(self.bottomContainer).offset(-KB_SAFE_BOTTOM - 15); + }]; + + [self.agreementLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerX.equalTo(self.bottomContainer); + make.bottom.equalTo(self.agreementButton.mas_top).offset(0); + }]; + + [self.payButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.bottomContainer).offset(24); + make.right.equalTo(self.bottomContainer).offset(-24); + make.bottom.equalTo(self.agreementLabel.mas_top).offset(-14); + make.top.equalTo(self.bottomContainer).offset(16); + make.height.mas_equalTo(58); + }]; } - (void)viewDidAppear:(BOOL)animated { @@ -159,8 +192,10 @@ static const CGFloat JXheightForHeaderInSection = 39; - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; - - self.pagerView.frame = self.view.bounds; + + // pagerView 底部留出底部按钮区域的空间 + CGFloat bottomHeight = self.bottomContainer.bounds.size.height; + self.pagerView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - bottomHeight); } #pragma mark - JXPagerViewDelegate @@ -231,6 +266,28 @@ static const CGFloat JXheightForHeaderInSection = 39; [self.navigationController popViewControllerAnimated:true]; } +- (void)onTapPayButton { + // 获取当前选中的子 VC,调用其支付方法 + NSInteger index = self.myCategoryView.selectedIndex; + if (index == 0) { + // VIP 页面 + KBVipPay *vipVC = (KBVipPay *)[self.pagerView.listContainerView.validListDict objectForKey:@(index)]; + if ([vipVC respondsToSelector:@selector(onTapPayButton)]) { + [vipVC onTapPayButton]; + } + } else { + // SVIP 页面 + KBPaySvipVC *svipVC = (KBPaySvipVC *)[self.pagerView.listContainerView.validListDict objectForKey:@(index)]; + if ([svipVC respondsToSelector:@selector(onTapPayButton)]) { + [svipVC onTapPayButton]; + } + } +} + +- (void)onTapAgreementButton { + [KBHUD showInfo:KBLocalized(@"Open agreement")]; +} + - (void)onTapRestoreButton { [[KBMaiPointReporter sharedReporter] reportClickWithEventName:@"click_vip_restore_btn" pageId:@"vip_pay" @@ -277,4 +334,47 @@ static const CGFloat JXheightForHeaderInSection = 39; } return _restoreButton; } + +- (UIView *)bottomContainer { + if (!_bottomContainer) { + _bottomContainer = [UIView new]; + _bottomContainer.backgroundColor = [UIColor colorWithHex:0xF6F7FB]; + } + return _bottomContainer; +} + +- (UIButton *)payButton { + if (!_payButton) { + _payButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_payButton setTitle:KBLocalized(@"Recharge Now") forState:UIControlStateNormal]; + _payButton.titleLabel.font = [KBFont medium:15]; + _payButton.layer.cornerRadius = 29; + _payButton.clipsToBounds = YES; + _payButton.backgroundColor = [UIColor colorWithHex:0x222222]; + [_payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [_payButton addTarget:self action:@selector(onTapPayButton) forControlEvents:UIControlEventTouchUpInside]; + } + return _payButton; +} + +- (UILabel *)agreementLabel { + if (!_agreementLabel) { + _agreementLabel = [UILabel new]; + _agreementLabel.text = KBLocalized(@"By Clicking \"pay\", You Indicate Your Agreement To The"); + _agreementLabel.font = [KBFont regular:12]; + _agreementLabel.textColor = [UIColor colorWithHex:KBBlackValue]; + } + return _agreementLabel; +} + +- (UIButton *)agreementButton { + if (!_agreementButton) { + _agreementButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_agreementButton setTitle:KBLocalized(@"《Embership Agreement》") forState:UIControlStateNormal]; + [_agreementButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; + _agreementButton.titleLabel.font = [KBFont regular:12]; + [_agreementButton addTarget:self action:@selector(onTapAgreementButton) forControlEvents:UIControlEventTouchUpInside]; + } + return _agreementButton; +} @end diff --git a/keyBoard/Class/Pay/VC/KBPaySvipVC.h b/keyBoard/Class/Pay/VC/KBPaySvipVC.h index 493a27a..19a085a 100644 --- a/keyBoard/Class/Pay/VC/KBPaySvipVC.h +++ b/keyBoard/Class/Pay/VC/KBPaySvipVC.h @@ -12,6 +12,9 @@ NS_ASSUME_NONNULL_BEGIN @interface KBPaySvipVC : UIViewController +/// 外部调用支付 +- (void)onTapPayButton; + @end NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/Pay/VC/KBPaySvipVC.m b/keyBoard/Class/Pay/VC/KBPaySvipVC.m index e998e33..2ca817e 100644 --- a/keyBoard/Class/Pay/VC/KBPaySvipVC.m +++ b/keyBoard/Class/Pay/VC/KBPaySvipVC.m @@ -24,9 +24,6 @@ static NSString * const kKBSvipBenefitHeaderId = @"kKBSvipBenefitHeaderId"; /// 1:UI 控件 @property (nonatomic, strong) UICollectionView *collectionView; -@property (nonatomic, strong) UIButton *payButton; -@property (nonatomic, strong) UILabel *agreementLabel; -@property (nonatomic, strong) UIButton *agreementButton; /// 2:数据 @property (nonatomic, strong) NSArray *plans; @@ -55,32 +52,10 @@ static NSString * const kKBSvipBenefitHeaderId = @"kKBSvipBenefitHeaderId"; - (void)setupUI { self.view.backgroundColor = [UIColor colorWithHex:0xF6F7FB]; - [self.view addSubview:self.payButton]; - [self.view addSubview:self.agreementLabel]; - [self.view addSubview:self.agreementButton]; [self.view addSubview:self.collectionView]; - [self.agreementButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.centerX.equalTo(self.view); - make.bottom.equalTo(self.view).offset(-KB_SAFE_BOTTOM - 15); - }]; - - [self.agreementLabel mas_makeConstraints:^(MASConstraintMaker *make) { - make.centerX.equalTo(self.view); - make.bottom.equalTo(self.agreementButton.mas_top).offset(0); - }]; - - [self.payButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.left.equalTo(self.view).offset(24); - make.right.equalTo(self.view).offset(-24); - make.bottom.equalTo(self.agreementLabel.mas_top).offset(-14); - make.height.mas_equalTo(58); - }]; - [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { - make.left.right.equalTo(self.view); - make.top.equalTo(self.view).offset(16); - make.bottom.equalTo(self.payButton.mas_top).offset(-16); + make.edges.equalTo(self.view); }]; } @@ -213,10 +188,6 @@ static NSString * const kKBSvipBenefitHeaderId = @"kKBSvipBenefitHeaderId"; }]; } -- (void)agreementButtonAction { - [KBHUD showInfo:KBLocalized(@"Open agreement")]; -} - #pragma mark - UICollectionView DataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { @@ -411,40 +382,4 @@ static NSString * const kKBSvipBenefitHeaderId = @"kKBSvipBenefitHeaderId"; return _collectionView; } -- (UIButton *)payButton { - if (!_payButton) { - _payButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_payButton setTitle:KBLocalized(@"Recharge Now") forState:UIControlStateNormal]; - [_payButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal]; - _payButton.titleLabel.font = [KBFont medium:15]; - _payButton.layer.cornerRadius = 29; - _payButton.clipsToBounds = YES; - _payButton.backgroundColor = [UIColor colorWithHex:0x222222]; - [_payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - [_payButton addTarget:self action:@selector(onTapPayButton) forControlEvents:UIControlEventTouchUpInside]; - } - return _payButton; -} - -- (UILabel *)agreementLabel { - if (!_agreementLabel) { - _agreementLabel = [UILabel new]; - _agreementLabel.text = KBLocalized(@"By Clicking \"pay\", You Indicate Your Agreement To The"); - _agreementLabel.font = [KBFont regular:12]; - _agreementLabel.textColor = [UIColor colorWithHex:KBBlackValue]; - } - return _agreementLabel; -} - -- (UIButton *)agreementButton { - if (!_agreementButton) { - _agreementButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_agreementButton setTitle:KBLocalized(@"《Embership Agreement》") forState:UIControlStateNormal]; - [_agreementButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; - _agreementButton.titleLabel.font = [KBFont regular:12]; - [_agreementButton addTarget:self action:@selector(agreementButtonAction) forControlEvents:UIControlEventTouchUpInside]; - } - return _agreementButton; -} - @end diff --git a/keyBoard/Class/Pay/VC/KBVipPay.h b/keyBoard/Class/Pay/VC/KBVipPay.h index d4a4b2b..6b3259a 100644 --- a/keyBoard/Class/Pay/VC/KBVipPay.h +++ b/keyBoard/Class/Pay/VC/KBVipPay.h @@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN autoPurchase:(BOOL)autoPurchase prefillProductsJSON:(nullable NSArray *)productsJSON selectedIndex:(NSInteger)selectedIndex; + +/// 点击支付按钮(供外部调用) +- (void)onTapPayButton; @end NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/Pay/VC/KBVipPay.m b/keyBoard/Class/Pay/VC/KBVipPay.m index 478027f..44435b3 100644 --- a/keyBoard/Class/Pay/VC/KBVipPay.m +++ b/keyBoard/Class/Pay/VC/KBVipPay.m @@ -29,10 +29,6 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId"; // Header 自适应测量 @property (nonatomic, strong) KBVipPayHeaderView *sizingHeader; @property (nonatomic, assign) CGFloat headerHeight; -// 底部支付与协议 -@property (nonatomic, strong) UIButton *payButton; // 支付按钮(背景图) -@property (nonatomic, strong) UILabel *agreementLabel; // 协议提示 -@property (nonatomic, strong) UIButton *agreementButton; // 《Embership Agreement》 @property (nonatomic, strong) PayVM *payVM; @property (nonatomic, copy, nullable) NSString *pendingProductId; @property (nonatomic, assign) BOOL pendingAutoPurchase; @@ -67,28 +63,8 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId"; // 组装主列表 [self.view addSubview:self.collectionView]; - // 先添加底部按钮与协议,再让 collectionView 的底部在按钮之上 - [self.view addSubview:self.payButton]; - [self.view addSubview:self.agreementLabel]; - [self.view addSubview:self.agreementButton]; - [self.payButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.left.equalTo(self.view).offset(24); - make.right.equalTo(self.view).offset(-24); - make.bottom.equalTo(self.agreementLabel.mas_top).offset(-14); - make.height.mas_equalTo(58); - }]; - [self.agreementButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.centerX.equalTo(self.view); - make.bottom.equalTo(self.view).offset(-KB_SAFE_BOTTOM - 15); - }]; - [self.agreementLabel mas_makeConstraints:^(MASConstraintMaker *make) { - make.centerX.equalTo(self.view); - make.bottom.equalTo(self.agreementButton.mas_top).offset(0); - }]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { - make.left.right.equalTo(self.view); - make.top.equalTo(self.view).offset(0); - make.bottom.equalTo(self.payButton.mas_top).offset(-16); + make.edges.equalTo(self.view); }]; @@ -323,9 +299,7 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId"; [self selectCurrentPlanAnimated:NO]; }]; } -- (void)agreementButtonAction{ - [KBHUD showInfo:KBLocalized(@"Open agreement")]; -} + @@ -470,46 +444,7 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId"; -- (UIButton *)payButton { - if (!_payButton) { - _payButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_payButton setTitle:KBLocalized(@"Recharge Now") forState:UIControlStateNormal]; - [_payButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal]; -// _payButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold]; - _payButton.titleLabel.font = [KBFont medium:15]; - UIImage *bg = [UIImage imageNamed:@"recharge_now_icon"]; - if (bg) { - [_payButton setBackgroundImage:bg forState:UIControlStateNormal]; - } else { - // 兜底:纯代码渐变 - UIImage *fallback = [UIImage kb_gradientImageWithColors:@[[UIColor colorWithHex:0xC7F8F0], [UIColor colorWithHex:0xE8FFF6]] size:CGSizeMake(10, 58) direction:KBGradientDirectionLeftToRight]; - [_payButton setBackgroundImage:[fallback resizableImageWithCapInsets:UIEdgeInsetsMake(29, 29, 29, 29) resizingMode:UIImageResizingModeStretch] forState:UIControlStateNormal]; - } - [_payButton addTarget:self action:@selector(onTapPayButton) forControlEvents:UIControlEventTouchUpInside]; - } - return _payButton; -} -- (UILabel *)agreementLabel { - if (!_agreementLabel) { - _agreementLabel = [UILabel new]; - _agreementLabel.text = @"By clicking \"Pay\", you indicate your agreement to the"; - _agreementLabel.font = [KBFont regular:12]; - _agreementLabel.textColor = [UIColor colorWithHex:KBBlackValue]; - } - return _agreementLabel; -} - -- (UIButton *)agreementButton { - if (!_agreementButton) { - _agreementButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_agreementButton setTitle:@"《Embership Agreement》" forState:UIControlStateNormal]; - [_agreementButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; - _agreementButton.titleLabel.font = [KBFont regular:12]; - [_agreementButton addTarget:self action:@selector(agreementButtonAction) forControlEvents:UIControlEventTouchUpInside]; - } - return _agreementButton; -} - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews];