Skip to content

Commit

Permalink
add hide navbar e.g.
Browse files Browse the repository at this point in the history
  • Loading branch information
yongyuandouneng committed Jul 19, 2018
1 parent 7bea323 commit 9478a41
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
2E3F8DE720FA0C45009FDA84 /* YNPageCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E3F8DE620FA0C45009FDA84 /* YNPageCollectionView.m */; };
2E3F8DEB20FA112D009FDA84 /* YNSuspendTopPausePageVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E3F8DEA20FA112D009FDA84 /* YNSuspendTopPausePageVC.m */; };
2E3F8DEE20FA1304009FDA84 /* YNSuspendTopPauseBaseTableViewVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E3F8DED20FA1304009FDA84 /* YNSuspendTopPauseBaseTableViewVC.m */; };
2E3F8E8721002964009FDA84 /* YNSuspendCustomNavOrSuspendPositionVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E3F8E8621002963009FDA84 /* YNSuspendCustomNavOrSuspendPositionVC.m */; };
2E5F7D8020DCA5430069962B /* DemosListVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E5F7D7A20DCA5430069962B /* DemosListVC.m */; };
2E5F7D8120DCA5430069962B /* YNTestBaseVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E5F7D7D20DCA5430069962B /* YNTestBaseVC.m */; };
2E5F7D8220DCA5430069962B /* YNTestPageVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E5F7D7F20DCA5430069962B /* YNTestPageVC.m */; };
Expand Down Expand Up @@ -102,6 +103,8 @@
2E3F8DEA20FA112D009FDA84 /* YNSuspendTopPausePageVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YNSuspendTopPausePageVC.m; sourceTree = "<group>"; };
2E3F8DEC20FA1304009FDA84 /* YNSuspendTopPauseBaseTableViewVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YNSuspendTopPauseBaseTableViewVC.h; sourceTree = "<group>"; };
2E3F8DED20FA1304009FDA84 /* YNSuspendTopPauseBaseTableViewVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YNSuspendTopPauseBaseTableViewVC.m; sourceTree = "<group>"; };
2E3F8E8521002963009FDA84 /* YNSuspendCustomNavOrSuspendPositionVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YNSuspendCustomNavOrSuspendPositionVC.h; sourceTree = "<group>"; };
2E3F8E8621002963009FDA84 /* YNSuspendCustomNavOrSuspendPositionVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YNSuspendCustomNavOrSuspendPositionVC.m; sourceTree = "<group>"; };
2E5F7D7920DCA5430069962B /* DemosListVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemosListVC.h; sourceTree = "<group>"; };
2E5F7D7A20DCA5430069962B /* DemosListVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemosListVC.m; sourceTree = "<group>"; };
2E5F7D7C20DCA5430069962B /* YNTestBaseVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YNTestBaseVC.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -280,16 +283,26 @@
path = SuspendTopPausePageVC;
sourceTree = "<group>";
};
2E3F8E8421002952009FDA84 /* SuspendCustomNavOrSuspendPositionVC */ = {
isa = PBXGroup;
children = (
2E3F8E8521002963009FDA84 /* YNSuspendCustomNavOrSuspendPositionVC.h */,
2E3F8E8621002963009FDA84 /* YNSuspendCustomNavOrSuspendPositionVC.m */,
);
path = SuspendCustomNavOrSuspendPositionVC;
sourceTree = "<group>";
};
2E5F7D7820DCA5430069962B /* Demos */ = {
isa = PBXGroup;
children = (
2E5F7E9520DCA8A30069962B /* BaseVC */,
2E5F7E9C20DCABCC0069962B /* SuspendCenterPageVC */,
2E5F7E9D20DCABCC0069962B /* SuspendTopPageVC */,
2E3F8DE820FA10F1009FDA84 /* SuspendTopPausePageVC */,
2E3F8E8421002952009FDA84 /* SuspendCustomNavOrSuspendPositionVC */,
2EFDC1D620E213310018455F /* LoadPageVC */,
2E5F7E9920DCAA700069962B /* TopPageVC */,
2E5F7E9A20DCAA830069962B /* NavPageVC */,
2EFDC1D620E213310018455F /* LoadPageVC */,
2EFDC1D220E0E9980018455F /* ScrollMenuStyleVC */,
2E5F7D7B20DCA5430069962B /* TestPageVC */,
2E5F7D7920DCA5430069962B /* DemosListVC.h */,
Expand Down Expand Up @@ -755,6 +768,7 @@
2E5F7EA620DCEB2C0069962B /* BaseCollectionViewVC.m in Sources */,
2E5F7E9020DCA5860069962B /* UIImage+GIF.m in Sources */,
2E5F7D8020DCA5430069962B /* DemosListVC.m in Sources */,
2E3F8E8721002964009FDA84 /* YNSuspendCustomNavOrSuspendPositionVC.m in Sources */,
2EFDC1D520E0E9B10018455F /* YNScrollMenuStyleVC.m in Sources */,
2E5F7E9820DCA8AF0069962B /* BaseTableViewVC.m in Sources */,
2E5F7E8020DCA5860069962B /* TAAbstractDotView.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ - (NSInteger)getPageIndexWithTitle:(NSString *)title {
/// 回调监听列表滚动代理
- (void)invokeDelegateForScrollWithOffsetY:(CGFloat)offsetY {
if (self.delegate && [self.delegate respondsToSelector:@selector(pageViewController:contentOffsetY:progress:)]) {
CGFloat progress = 1 + (offsetY + self.scrollMenuView.yn_height) / (self.headerBgView.yn_height);
CGFloat progress = 1 + (offsetY + self.scrollMenuView.yn_height + self.config.suspenOffsetY) / (self.headerBgView.yn_height -self.config.suspenOffsetY);
[self.delegate pageViewController:self contentOffsetY:offsetY progress:progress > 1 ? 1 : progress];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (void)viewDidLoad {
_dataArray = @[].mutableCopy;
/// 加载数据
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 40; i++) {
[_dataArray addObject:@""];
}
[self.tableView reloadData];
Expand Down Expand Up @@ -166,7 +166,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

cell.textLabel.text = [NSString stringWithFormat:@"%@ section: %zd row:%zd", self.cellTitle ?: @"测试", indexPath.section, indexPath.row];
return cell;
}
} else {
cell.textLabel.text = @"";
}

return cell;

Expand Down
16 changes: 12 additions & 4 deletions YNPageViewController/YNPageViewController/Src/Demos/DemosListVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
#import "YNScrollMenuStyleVC.h"
#import "YNLoadPageVC.h"
#import "YNSuspendTopPausePageVC.h"
#import "YNSuspendCustomNavOrSuspendPositionVC.h"

typedef NS_ENUM(NSInteger, YNVCType) {
YNVCTypeSuspendCenterPageVC = 1,
YNVCTypeSuspendTopPageVC = 2,
YNVCTypeTopPageVC = 3,
YNVCTypeSuspendTopPausePageVC = 4,
YNVCTypeNavPageVC = 5,
YNVCTypeScrollMenuStyleVC = 6,
YNVCTypeLoadPageVC = 7,
YNVCTypeSuspendCustomNavOrSuspendPosition = 5,
YNVCTypeNavPageVC = 6,
YNVCTypeScrollMenuStyleVC = 7,
YNVCTypeLoadPageVC = 8,
YNVCTypeYNTestPageVC = 100
};

Expand All @@ -46,10 +48,11 @@ - (void)viewDidLoad {
self.dataArrayM = @[@{@"title" : @"悬浮样式--下拉刷新在中间", @"type" : @(YNVCTypeSuspendCenterPageVC)},
@{@"title" : @"悬浮样式--下拉刷新在顶部", @"type" : @(YNVCTypeSuspendTopPageVC)},
@{@"title" : @"悬浮样式--下拉刷新在顶部(QQ联系人样式)", @"type" : @(YNVCTypeSuspendTopPausePageVC)},
@{@"title" : @"悬浮样式--自定义导航条或自定义悬浮位置", @"type" : @(YNVCTypeSuspendCustomNavOrSuspendPosition)},
@{@"title" : @"加载数据后显示页面(隐藏导航条)", @"type" : @(YNVCTypeLoadPageVC)},
@{@"title" : @"顶部样式", @"type" : @(YNVCTypeTopPageVC)},
@{@"title" : @"导航条样式", @"type" : @(YNVCTypeNavPageVC)},
@{@"title" : @"菜单栏样式", @"type" : @(YNVCTypeScrollMenuStyleVC)},
@{@"title" : @"加载数据后显示页面(隐藏导航条)", @"type" : @(YNVCTypeLoadPageVC)},
@{@"title" : @"测试专用", @"type" : @(YNVCTypeYNTestPageVC)}
].mutableCopy;
}
Expand Down Expand Up @@ -132,6 +135,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
vc = [YNSuspendTopPausePageVC suspendTopPausePageVC];
}
break;
case YNVCTypeSuspendCustomNavOrSuspendPosition:
{
vc = [YNSuspendCustomNavOrSuspendPositionVC new];
}
break;
case YNVCTypeTopPageVC:
{
vc = [YNTopPageVC topPageVC];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ + (instancetype)suspendCenterPageVC {
configration.aligmentModeCenter = NO;
configration.lineWidthEqualFontWidth = NO;
configration.showBottomLine = YES;
configration.suspenOffsetY = 64;

return [self suspendCenterPageVCWithConfig:configration];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// YNSuspendCustomNavOrSuspendPositionVC.h
// YNPageViewController
//
// Created by ZYN on 2018/7/19.
// Copyright © 2018年 yongneng. All rights reserved.
//

#import "BaseViewController.h"

@interface YNSuspendCustomNavOrSuspendPositionVC : BaseViewController


@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//
// YNSuspendCustomNavOrSuspendPositionVC.m
// YNPageViewController
//
// Created by ZYN on 2018/7/19.
// Copyright © 2018年 yongneng. All rights reserved.
//

#import "YNSuspendCustomNavOrSuspendPositionVC.h"
#import "YNPageViewController.h"
#import "UIView+YNPageExtend.h"
#import "BaseTableViewVC.h"
#import "BaseCollectionViewVC.h"
#import "SDCycleScrollView.h"

@interface YNSuspendCustomNavOrSuspendPositionVC () <YNPageViewControllerDataSource, YNPageViewControllerDelegate, SDCycleScrollViewDelegate>

@property (nonatomic, strong) UIActivityIndicatorView *indicatorView;

@property (nonatomic, copy) NSArray *imagesURLs;

@property (nonatomic, strong) UIView *navView;

@end

@implementation YNSuspendCustomNavOrSuspendPositionVC

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[self.navigationController setNavigationBarHidden:YES animated:animated];

}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];

[self.navigationController setNavigationBarHidden:NO animated:animated];

}

- (void)viewDidLoad {
[super viewDidLoad];
_indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_indicatorView.frame = CGRectMake(0, 0, 80, 80);
_indicatorView.center = self.view.center;
[_indicatorView startAnimating];

/// 模拟器请求
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[self setupPageVC];

[_indicatorView stopAnimating];
[_indicatorView setHidden:YES];
});

[self.view addSubview:_indicatorView];
}

- (void)setupPageVC {

YNPageConfigration *configration = [YNPageConfigration defaultConfig];
configration.pageStyle = YNPageStyleSuspensionCenter;
configration.headerViewCouldScale = YES;
/// 控制tabbar 和 nav
configration.showTabbar = NO;
configration.showNavigation = NO;
configration.scrollMenu = NO;
configration.aligmentModeCenter = NO;
configration.lineWidthEqualFontWidth = NO;
configration.showBottomLine = YES;
/// 设置悬浮停顿偏移量
configration.suspenOffsetY = kYNPAGE_NAVHEIGHT;


YNPageViewController *vc = [YNPageViewController pageViewControllerWithControllers:self.getArrayVCs
titles:[self getArrayTitles]
config:configration];
vc.dataSource = self;
vc.delegate = self;
/// 轮播图
SDCycleScrollView *autoScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 200) imageURLStringsGroup:self.imagesURLs];
autoScrollView.delegate = self;

vc.headerView = autoScrollView;
/// 指定默认选择index 页面
vc.pageIndex = 2;


/// 作为自控制器加入到当前控制器
[vc addSelfToParentViewController:self];

/// 如果隐藏了导航条可以 适当改y值
// pageVC.view.yn_y = kYNPAGE_NAVHEIGHT;

[self.view addSubview:self.navView];

}

- (NSArray *)getArrayVCs {

BaseTableViewVC *vc_1 = [[BaseTableViewVC alloc] init];
vc_1.cellTitle = @"鞋子";

BaseTableViewVC *vc_2 = [[BaseTableViewVC alloc] init];
vc_2.cellTitle = @"衣服";

BaseCollectionViewVC *vc_3 = [[BaseCollectionViewVC alloc] init];

return @[vc_1, vc_2, vc_3];
}

- (NSArray *)getArrayTitles {
return @[@"鞋子", @"衣服", @"帽子"];
}

- (UIView *)navView {
if (!_navView) {
_navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kYNPAGE_NAVHEIGHT)];
_navView.backgroundColor = RGBA(246, 246, 246, 0);
}
return _navView;
}

#pragma mark - Private Function

#pragma mark - Getter and Setter
- (NSArray *)imagesURLs {
if (!_imagesURLs) {
_imagesURLs = @[
@"https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a4b3d7085dee3d6d2293d48b252b5910/0e2442a7d933c89524cd5cd4d51373f0830200ea.jpg",
@"https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg",
@"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"];
}
return _imagesURLs;
}
#pragma mark - YNPageViewControllerDataSource
- (UIScrollView *)pageViewController:(YNPageViewController *)pageViewController pageForIndex:(NSInteger)index {
UIViewController *vc = pageViewController.controllersM[index];
if ([vc isKindOfClass:[BaseTableViewVC class]]) {
return [(BaseTableViewVC *)vc tableView];
} else {
return [(BaseCollectionViewVC *)vc collectionView];
}
}
#pragma mark - YNPageViewControllerDelegate
- (void)pageViewController:(YNPageViewController *)pageViewController
contentOffsetY:(CGFloat)contentOffset
progress:(CGFloat)progress {
NSLog(@"--- contentOffset = %f, progress = %f", contentOffset, progress);

self.navView.backgroundColor = RGBA(246, 246, 246, progress);

}


#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
NSLog(@"----click 轮播图 index %ld", index);
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ + (instancetype)suspendTopPageVC {
configration.aligmentModeCenter = NO;
configration.lineWidthEqualFontWidth = NO;
configration.showBottomLine = YES;
configration.suspenOffsetY = 64;

YNSuspendTopPageVC *vc = [YNSuspendTopPageVC pageViewControllerWithControllers:[self getArrayVCs]
titles:[self getArrayTitles]
config:configration];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ - (void)addTableViewRefresh {
/// 这里加 footer 刷新
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 30; i++) {
[self.dataArray addObject:@""];
}
[self.tableView reloadData];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (void)viewDidLoad {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd));
[self.navigationController setNavigationBarHidden:YES animated:animated];
// [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewDidAppear:(BOOL)animated {
Expand All @@ -41,7 +41,7 @@ - (void)viewDidAppear:(BOOL)animated {
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd));
[self.navigationController setNavigationBarHidden:NO animated:animated];
// [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
Expand All @@ -67,16 +67,15 @@ - (void)viewDidDisappear:(BOOL)animated {
+ (instancetype)suspendTopPausePageVC {

YNPageConfigration *configration = [YNPageConfigration defaultConfig];

configration.pageStyle = YNPageStyleSuspensionTopPause;
configration.headerViewCouldScale = YES;
configration.showTabbar = NO;
configration.showNavigation = NO;
configration.showNavigation = YES;
configration.scrollMenu = NO;
configration.aligmentModeCenter = NO;
configration.lineWidthEqualFontWidth = NO;
configration.showBottomLine = YES;
configration.suspenOffsetY = 64;

YNSuspendTopPausePageVC *vc = [YNSuspendTopPausePageVC pageViewControllerWithControllers:[self getArrayVCs]
titles:[self getArrayTitles]
config:configration];
Expand Down
2 changes: 2 additions & 0 deletions YNPageViewController/YNPageViewController/YNPreHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define kSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define kSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define RGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]

#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]

#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
Expand Down

0 comments on commit 9478a41

Please sign in to comment.