224 lines
9.2 KiB
Objective-C
224 lines
9.2 KiB
Objective-C
//
|
|
// XPHomePagingViewController.m
|
|
// YuMi
|
|
//
|
|
// Created by P on 2024/6/16.
|
|
//
|
|
|
|
#import "XPHomePagingViewController.h"
|
|
|
|
#import "XPNewHomeViewController.h"
|
|
#import "XPHomeMineViewController.h"
|
|
#import "XPRoomSearchContainerViewController.h"
|
|
|
|
#import "Api+Gift.h"
|
|
#import "XPGiftStorage.h"
|
|
|
|
@interface XPHomePagingViewController () <UIPageViewControllerDelegate, UIPageViewControllerDataSource>
|
|
|
|
@property (nonatomic, strong) UIView *topControlView;
|
|
@property (nonatomic, strong) UIButton *mineButton;
|
|
@property (nonatomic, strong) UIButton *recommendButton;
|
|
|
|
@property (nonatomic, strong) UIPageViewController *pageContainer;
|
|
@property (nonatomic, strong) NSArray *viewControllers; // 存储子视图控制器的数组
|
|
@property (nonatomic, assign) NSUInteger currentIndex; // 当前显示的页面索引
|
|
|
|
@property (nonatomic, strong) XPNewHomeViewController *recommendVC;
|
|
@property (nonatomic, strong) XPHomeMineViewController *mineVC;
|
|
|
|
@end
|
|
|
|
@implementation XPHomePagingViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self setup];
|
|
[self preLoadGifts];
|
|
|
|
//#if DEBUG
|
|
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
// [self performSelector:@selector(completeUserInfo)];
|
|
// });
|
|
//#endif
|
|
}
|
|
|
|
/// 禮物面板緩存-1: 登錄後,用空的 roomUid 預加載默認禮物,並緩存
|
|
- (void)preLoadGifts {
|
|
[Api requestAllTagsAndNormalGifts:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200 && data.data) {
|
|
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
[[XPGiftStorage shareStorage] cacheTagsWith:data.data
|
|
inRoom:[[XPGiftStorage shareStorage] defaultKey]];
|
|
});
|
|
}
|
|
} roomUid:@""];
|
|
}
|
|
|
|
- (void)setup {
|
|
|
|
self.view.backgroundColor = [[ClientConfig shareConfig] bgColor];
|
|
|
|
[self setupTopTheme];
|
|
[self setupTopControl];
|
|
|
|
_pageContainer = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
|
|
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
|
|
options:nil];
|
|
_pageContainer.delegate = self;
|
|
_pageContainer.dataSource = self;
|
|
_recommendVC = [[XPNewHomeViewController alloc] init];
|
|
_mineVC = [[XPHomeMineViewController alloc] init];
|
|
_viewControllers = @[_recommendVC, _mineVC];
|
|
[self didTapRecommendButton];
|
|
|
|
[self addChildViewController:_pageContainer];
|
|
[self.view addSubview:_pageContainer.view];
|
|
|
|
[self.pageContainer.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.bottom.trailing.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.topControlView.mas_bottom);
|
|
}];
|
|
[self.pageContainer didMoveToParentViewController:self];
|
|
|
|
for (UIView *view in self.pageContainer.view.subviews) {
|
|
if ([view isKindOfClass:[UIScrollView class]]) {
|
|
UIScrollView *scrollView = (UIScrollView *)view;
|
|
scrollView.scrollEnabled = NO; // 禁用滚动
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)setupTopTheme {
|
|
__block UIImageView *theme = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kGetScaleWidth(140))];
|
|
theme.image = [[ClientConfig shareConfig] navigationAreaBG];
|
|
theme.contentMode = UIViewContentModeScaleAspectFill;
|
|
[self.view addSubview:theme];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:[ClientConfig shareConfig].reloadNavigationAreaImageKey
|
|
object:nil
|
|
queue:[NSOperationQueue mainQueue]
|
|
usingBlock:^(NSNotification * _Nonnull notification) {
|
|
if ([notification.object isKindOfClass:[UIImage class]]) {
|
|
theme.image = (UIImage *)notification.object;
|
|
}
|
|
}];
|
|
}
|
|
|
|
- (void)setupTopControl {
|
|
_topControlView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
|
|
KScreenWidth,
|
|
44+[UIApplication sharedApplication].keyWindow.safeAreaInsets.top)];
|
|
_topControlView.backgroundColor = [UIColor clearColor];
|
|
[self.view addSubview:_topControlView];
|
|
|
|
_recommendButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_recommendButton setTitle:YMLocalizedString(@"XPMonentsViewController2") forState:UIControlStateNormal];
|
|
[_recommendButton addTarget:self
|
|
action:@selector(didTapRecommendButton)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[_topControlView addSubview:_recommendButton];
|
|
[_recommendButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.topControlView);//.offset(-8);
|
|
make.width.mas_greaterThanOrEqualTo(40);
|
|
make.leading.mas_equalTo(self.topControlView).offset(16);
|
|
}];
|
|
|
|
_mineButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_mineButton setTitle:YMLocalizedString(@"TabbarViewController5") forState:UIControlStateNormal];
|
|
[_mineButton addTarget:self
|
|
action:@selector(didTapMineButton)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[_topControlView addSubview:_mineButton];
|
|
[_mineButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.topControlView);//.offset(-8);
|
|
make.width.mas_greaterThanOrEqualTo(40);
|
|
make.leading.mas_equalTo(_recommendButton.mas_trailing).offset(32);
|
|
}];
|
|
|
|
UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[searchButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
[searchButton setBackgroundImage:[UIImage imageNamed:@"home_nav_search"] forState:UIControlStateNormal];
|
|
[searchButton addTarget:self
|
|
action:@selector(didTapSearchButton)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[_topControlView addSubview:searchButton];
|
|
[searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.mineButton);
|
|
make.trailing.mas_equalTo(self.topControlView).offset(-16);
|
|
make.width.height.mas_equalTo(28);
|
|
}];
|
|
}
|
|
|
|
- (void)displayMineTab {
|
|
[_mineButton.titleLabel setFont:kFontBold(20)];
|
|
[_recommendButton.titleLabel setFont:kFontRegular(16)];
|
|
[_mineButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
|
[_recommendButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
|
}
|
|
|
|
- (void)displayRecommendTab {
|
|
[_mineButton.titleLabel setFont:kFontRegular(16)];
|
|
[_recommendButton.titleLabel setFont:kFontBold(20)];
|
|
[_recommendButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
|
[_mineButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
|
}
|
|
|
|
#pragma mark -
|
|
- (void)didTapMineButton {
|
|
[self.pageContainer setViewControllers:@[self.viewControllers[1]]
|
|
direction:UIPageViewControllerNavigationDirectionReverse
|
|
animated:NO
|
|
completion:nil];
|
|
[self displayMineTab];
|
|
}
|
|
|
|
- (void)didTapRecommendButton {
|
|
[self.pageContainer setViewControllers:@[self.viewControllers[0]]
|
|
direction:UIPageViewControllerNavigationDirectionForward
|
|
animated:NO
|
|
completion:nil];
|
|
[self displayRecommendTab];
|
|
}
|
|
|
|
- (void)didTapSearchButton {
|
|
XPRoomSearchContainerViewController * searchVC = [[XPRoomSearchContainerViewController alloc] init];
|
|
searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
[self.navigationController presentViewController:searchVC
|
|
animated:YES
|
|
completion:nil];
|
|
}
|
|
|
|
#pragma mark - UIPageViewController Delegate & DataSource
|
|
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
|
|
// NSUInteger index = [self.viewControllers indexOfObject:viewController];
|
|
// if (index > 0) {
|
|
// return self.viewControllers[index - 1];
|
|
// }
|
|
return nil;
|
|
}
|
|
|
|
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
|
|
// NSUInteger index = [self.viewControllers indexOfObject:viewController];
|
|
// if (index < self.viewControllers.count - 1) {
|
|
// return self.viewControllers[index + 1];
|
|
// }
|
|
return nil;
|
|
}
|
|
|
|
#pragma mark - UIPageViewControllerDelegate
|
|
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers {
|
|
// 更新当前索引
|
|
self.currentIndex = [self.viewControllers indexOfObject:pendingViewControllers.firstObject];
|
|
if (self.currentIndex == 0) {
|
|
[self displayMineTab];
|
|
} else {
|
|
[self displayRecommendTab];
|
|
}
|
|
}
|
|
@end
|