236 lines
9.5 KiB
Objective-C
236 lines
9.5 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"
|
|
|
|
@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) UIImageView *tabMarks;
|
|
|
|
@property (nonatomic, strong) XPNewHomeViewController *recommendVC;
|
|
@property (nonatomic, strong) XPHomeMineViewController *mineVC;
|
|
|
|
@end
|
|
|
|
@implementation XPHomePagingViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self setup];
|
|
}
|
|
|
|
- (void)setup {
|
|
|
|
self.view.backgroundColor = [DJDKMIMOMColor colorWithHexString:@"#F3F5FA"];
|
|
|
|
[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.left.bottom.right.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 {
|
|
UIImageView *theme = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kGetScaleWidth(223))];
|
|
theme.image = [UIImage imageNamed:@"home_top_bg"];
|
|
theme.contentMode = UIViewContentModeScaleAspectFill;
|
|
[self.view addSubview:theme];
|
|
}
|
|
|
|
- (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);
|
|
if (isMSRTL()) {
|
|
make.right.mas_equalTo(self.topControlView).offset(-16);
|
|
} else {
|
|
make.left.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);
|
|
if (isMSRTL()) {
|
|
make.right.mas_equalTo(_recommendButton.mas_left).offset(-32);
|
|
} else {
|
|
make.left.mas_equalTo(_recommendButton.mas_right).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);
|
|
if (isMSRTL()) {
|
|
make.left.mas_equalTo(self.topControlView).offset(16);
|
|
} else {
|
|
make.right.mas_equalTo(self.topControlView).offset(-16);
|
|
}
|
|
make.width.height.mas_equalTo(16);
|
|
}];
|
|
|
|
_tabMarks = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_top_tab_marks"]];
|
|
_tabMarks.contentMode = UIViewContentModeScaleAspectFill;
|
|
[_topControlView addSubview:_tabMarks];
|
|
[_tabMarks mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.topControlView).offset(-8);
|
|
make.width.mas_equalTo(14);
|
|
make.height.mas_equalTo(4);
|
|
make.centerX.mas_equalTo(self.recommendButton.mas_centerX);
|
|
}];
|
|
}
|
|
|
|
- (void)displayMineTab {
|
|
[_mineButton.titleLabel setFont:kFontBold(21)];
|
|
[_recommendButton.titleLabel setFont:kFontBold(18)];
|
|
[_mineButton setTitleColor:UIColorRGBAlpha(0x0c1d18, 1) forState:UIControlStateNormal];
|
|
[_recommendButton setTitleColor:UIColorRGBAlpha(0x0c1d18, 0.6) forState:UIControlStateNormal];
|
|
|
|
// [UIView animateWithDuration:0.25 animations:^{
|
|
[self.tabMarks mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.topControlView).offset(-8);
|
|
make.width.mas_equalTo(14);
|
|
make.height.mas_equalTo(4);
|
|
make.centerX.mas_equalTo(self.mineButton.mas_centerX);
|
|
}];
|
|
// [self.view setNeedsLayout];
|
|
// }];
|
|
}
|
|
|
|
- (void)displayRecommendTab {
|
|
[_mineButton.titleLabel setFont:kFontBold(18)];
|
|
[_recommendButton.titleLabel setFont:kFontBold(21)];
|
|
[_recommendButton setTitleColor:UIColorRGBAlpha(0x0c1d18, 1) forState:UIControlStateNormal];
|
|
[_mineButton setTitleColor:UIColorRGBAlpha(0x0c1d18, 0.6) forState:UIControlStateNormal];
|
|
|
|
// [UIView animateWithDuration:0.25 animations:^{
|
|
[self.tabMarks mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.topControlView).offset(-8);
|
|
make.width.mas_equalTo(14);
|
|
make.height.mas_equalTo(4);
|
|
make.centerX.mas_equalTo(self.recommendButton.mas_centerX);
|
|
}];
|
|
// [self.view setNeedsLayout];
|
|
// }];
|
|
}
|
|
|
|
#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
|