You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.8 KiB
75 lines
1.8 KiB
4 years ago
|
//
|
||
|
// TFNavigationController.m
|
||
|
// WXReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/1.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFNavigationController.h"
|
||
|
#import "UINavigationController+TFExtension.h"
|
||
|
|
||
|
@interface TFNavigationController ()<UINavigationControllerDelegate>
|
||
|
|
||
|
@property (nonatomic ,assign) BOOL isSwitching;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFNavigationController
|
||
|
|
||
|
- (void)viewDidLoad
|
||
|
{
|
||
|
[super viewDidLoad];
|
||
|
|
||
|
self.delegate = self;
|
||
|
|
||
|
// 使导航条有效
|
||
|
[self setNavigationBarHidden:NO];
|
||
|
[self.navigationBar setHidden:YES];
|
||
|
}
|
||
|
|
||
|
- (void)setEnableSlidingBack:(BOOL)enableSlidingBack
|
||
|
{
|
||
|
_enableSlidingBack = enableSlidingBack;
|
||
|
|
||
|
self.interactivePopGestureRecognizer.enabled = enableSlidingBack;
|
||
|
}
|
||
|
|
||
|
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
|
||
|
{
|
||
|
if (self.viewControllers.count > 0 && !self.isTransition) {
|
||
|
viewController.hidesBottomBarWhenPushed = YES;
|
||
|
}
|
||
|
|
||
|
if (animated) {
|
||
|
if (self.isSwitching) {
|
||
|
return; // 1. 如果是动画,并且正在切换,直接忽略
|
||
|
}
|
||
|
self.isSwitching = YES; // 2. 否则修改状态
|
||
|
}
|
||
|
|
||
|
[super pushViewController:viewController animated:animated];
|
||
|
|
||
|
self.isSwitching = NO;
|
||
|
self.isTransition = NO;
|
||
|
}
|
||
|
|
||
|
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
|
||
|
{
|
||
|
BOOL isRootVC = viewController == navigationController.viewControllers.firstObject;
|
||
|
|
||
|
if (self.enableSlidingBack) {
|
||
|
self.enableSlidingBack = !isRootVC;
|
||
|
}
|
||
|
self.isSwitching = NO; // 3. 还原状态
|
||
|
}
|
||
|
|
||
|
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
|
||
|
{
|
||
|
self.isSwitching = NO;
|
||
|
|
||
|
return [super popViewControllerAnimated:animated];
|
||
|
}
|
||
|
|
||
|
@end
|