cdts/xdts-ios 3/TreeHole/Code/Features/NearAndLantern/THNearAndLanternViewController.m
2023-07-27 09:20:00 +08:00

294 lines
12 KiB
Objective-C

//
// THNearAndLanternViewController.m
// TreeHole
//
// Created by 郑创权 on 2023/5/7.
// Copyright © 2023 CYH. All rights reserved.
//
#import "THNearAndLanternViewController.h"
#import "THLanternAnimationController.h"
#import "BottleNerbyViewController.h"
#import "InviteCodeViewController.h"
#import "BottleTypePickerViewController.h"
@interface THNearAndLanternViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong)BottleNerbyViewController *BottleNerbyVC;
@property (nonatomic, strong)THLanternAnimationController *THLanternAnimationVC;
@property (nonatomic, strong)UIScrollView* scrollView;
@property (nonatomic, strong)UIView* titleView;
@end
@implementation THNearAndLanternViewController
- (BOOL)isSupportContentScrollView {
return YES;
}
- (BOOL)mt_nagationBarTransparent{
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.titleView = self.titleView;
UIImageView *bgImgView = [UIImageView new];
bgImgView.frame = self.view.bounds;
bgImgView.image = UIImageMake(@"TH_MineBg");
[self.view insertSubview:bgImgView atIndex:0];
[self setUpChildViewController];
WeakSelf(self);
QMUIButton *leftItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_GetVip_nav") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
[leftItemBtn addTapWithAction:^{
[weakself toInviteCodeViewController];
}];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftItemBtn];
QMUIButton *rightItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_navItemBottlePublic") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
[rightItemBtn addTapWithAction:^{
[weakself toChooseBottleTypeAndPublishVC];
}];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItemBtn];
}
-(UIView *)titleView{
if(!_titleView){
_titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 110, 44)];
// _titleView.backgroundColor = [UIColor whiteColor];
NSArray* titleArray = @[@"推荐",@"附近"];
for(NSInteger i = 0; i < 2 ; i++){
UIButton* titleBtn = [[UIButton alloc]initWithFrame:CGRectMake(i*55, 0, 55, 44)];
titleBtn.tag = 200000+i;
[titleBtn setTitle:titleArray[i] forState:UIControlStateNormal];
[titleBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
titleBtn.titleLabel.font = FONT_BOLD_SIZE(16);
if(i == 1){
[titleBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
titleBtn.titleLabel.font = FONT_SIZE(16);
}
[titleBtn addTarget:self action:@selector(titleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[_titleView addSubview:titleBtn];
if(i == 0){
UIView* redHLineV = [[UIView alloc]initWithFrame:CGRectMake(0, titleBtn.bottom - FIX_SIZE(5), FIX_SIZE(20), FIX_SIZE(2))];
redHLineV.backgroundColor = HEX_COLOR(0xf74c31);
[_titleView addSubview:redHLineV];
redHLineV.centerX = titleBtn.centerX;
redHLineV.tag = 200011;
}
}
}
return _titleView;
}
- (UIScrollView *)scrollView {
if (!_scrollView) {
// CGFloat scrollView_y = isIphoneX?64:44;
CGRect frame = CGRectMake(0, 0, self.view.width, self.view.height);
_scrollView = [[UIScrollView alloc] init];
_scrollView.autoresizesSubviews=YES;
// _scrollView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
_scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if (@available(iOS 13.0, *)) {
_scrollView.automaticallyAdjustsScrollIndicatorInsets = NO;
} else {
// Fallback on earlier versions
}
_scrollView.frame = frame;
_scrollView.delegate = self;
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.contentSize = CGSizeMake(_scrollView.width * 2, 0);
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.bounces = NO;
_scrollView.pagingEnabled = YES;
_scrollView.scrollEnabled = YES;
[self.view addSubview:_scrollView];
}
return _scrollView;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"scrollView.x : %.f",scrollView.contentOffset.x);
if(scrollView.contentOffset.x == 0){
UIButton* jiDiBtn = (UIButton*)[self.titleView viewWithTag:200000];
[jiDiBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
jiDiBtn.titleLabel.font = FONT_BOLD_SIZE(16);
UIButton* nearBtn = (UIButton*)[self.titleView viewWithTag:200001];
[nearBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
nearBtn.titleLabel.font = FONT_SIZE(16);
// [self.scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
UIView* redHLineV = (UIView*)[self.titleView viewWithTag:200011];
[UIView animateWithDuration:0.3 animations:^{
redHLineV.centerX = jiDiBtn.centerX;
}];
WeakSelf(self);
QMUIButton *leftItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_GetVip_nav") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
[leftItemBtn addTapWithAction:^{
[weakself toInviteCodeViewController];
}];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftItemBtn];
QMUIButton *rightItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_navItemBottlePublic") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
[rightItemBtn addTapWithAction:^{
[weakself toChooseBottleTypeAndPublishVC];
}];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItemBtn];
}
if(scrollView.contentOffset.x == SCREEN_WIDTH){
UIButton* jiDiBtn = (UIButton*)[self.titleView viewWithTag:200000];
[jiDiBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
jiDiBtn.titleLabel.font = FONT_SIZE(16);
UIButton* nearBtn = (UIButton*)[self.titleView viewWithTag:200001];
[nearBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
nearBtn.titleLabel.font =FONT_BOLD_SIZE(16);
// [self.scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
// [self.scrollView setContentOffset:CGPointMake(self.scrollView.width, 0) animated:NO];
UIView* redHLineV = (UIView*)[self.titleView viewWithTag:200011];
[UIView animateWithDuration:0.3 animations:^{
redHLineV.centerX = nearBtn.centerX;
}];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:_BottleNerbyVC.leftView];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:_BottleNerbyVC.navBottleBtn];
}
}
#pragma mark-添加两个子控制器
- (void)setUpChildViewController {
_THLanternAnimationVC = [[THLanternAnimationController alloc] init];
_BottleNerbyVC = [[BottleNerbyViewController alloc] init];
[self addChildViewController:_THLanternAnimationVC];
[self addChildViewController:_BottleNerbyVC];
[_THLanternAnimationVC didMoveToParentViewController:self];
[_BottleNerbyVC didMoveToParentViewController:self];
_THLanternAnimationVC.view.frame = CGRectMake(0,
0,
self.scrollView.width,
self.scrollView.height);
_BottleNerbyVC.view.frame = CGRectMake(self.scrollView.width,
0,
self.scrollView.width,
self.scrollView.height);
[self.scrollView addSubview:_THLanternAnimationVC.view];
[self.scrollView addSubview:_BottleNerbyVC.view];
// _shoppingOrdorVC = shoppingOrdorVC;
// _listenOrdorVC = listenOrdorVC;
}
-(void)titleBtnClick:(UIButton*)sender{
if([sender.titleLabel.text isEqualToString:@"推荐"]){
[sender setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
sender.titleLabel.font = FONT_BOLD_SIZE(16);
UIButton* nearBtn = (UIButton*)[self.titleView viewWithTag:200001];
[nearBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
nearBtn.titleLabel.font = FONT_SIZE(16);
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
WeakSelf(self);
QMUIButton *leftItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_GetVip_nav") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
[leftItemBtn addTapWithAction:^{
[weakself toInviteCodeViewController];
}];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftItemBtn];
QMUIButton *rightItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_navItemBottlePublic") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
[rightItemBtn addTapWithAction:^{
[weakself toChooseBottleTypeAndPublishVC];
}];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItemBtn];
}else{
[sender setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
sender.titleLabel.font = FONT_BOLD_SIZE(16);
UIButton* nearBtn = (UIButton*)[self.titleView viewWithTag:200000];
[nearBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
nearBtn.titleLabel.font = FONT_SIZE(16);
[self.scrollView setContentOffset:CGPointMake(self.scrollView.width, 0) animated:NO];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:_BottleNerbyVC.leftView];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:_BottleNerbyVC.navBottleBtn];
}
}
///领会员
- (void)toInviteCodeViewController {
InviteCodeViewController *inviteVC = [InviteCodeViewController new];
[self.navigationController pushViewController:inviteVC animated:YES];
}
///发布
- (void)toChooseBottleTypeAndPublishVC {
WeakSelf(self);
BottleTypePickerViewController *picker = [BottleTypePickerViewController pickerViewControllerWithCompletion:^(BottleTypePickerViewController * _Nonnull picker, BottleTypeInfo * _Nonnull info) {
[picker.navigationController dismissViewControllerAnimated:NO completion:^{
BottlePublishViewController *publishVC = [[BottlePublishViewController alloc] init];
publishVC.info = info;
publishVC.publishSucceedAction = ^{
// if (weakself.info.left_bottle_num > 0) {
// weakself.info.left_bottle_num --;
// [weakself reloadHurlBottoleButtonBadge];
// }
};
[weakself.navigationController presentViewController:[[PYNavigationViewController alloc] initWithRootViewController:publishVC] animated:YES completion:nil];
}];
}];
THNavigationController *nav = [[THNavigationController alloc] initWithRootViewController:picker];
[[PYAppService currentNavigationController] presentViewController:nav animated:YES completion:nil];
}
@end