123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // CustomNavViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "CustomNavViewController.h"
- #import <UIImage+Color.h>
- @interface CustomNavViewController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>
- @end
- @implementation CustomNavViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- KSWeakSelf(weakSelf);
- if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.interactivePopGestureRecognizer.delegate = weakSelf;
- self.delegate = weakSelf;
- if (@available(iOS 13.0, *)) {
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- [appearance configureWithOpaqueBackground];
- // 去掉半透明效果
-
- appearance.backgroundEffect = nil;
- // 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
- appearance.shadowImage = [UIImage imageWithColor:[UIColor clearColor]];
- appearance.backgroundColor = [UIColor whiteColor];
- [appearance setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]}];
- self.navigationBar.standardAppearance = appearance;
- self.navigationBar.scrollEdgeAppearance = appearance;
- }
- else {
- [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
- UINavigationBar *navBar = [UINavigationBar appearance];
- [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]}];
- [navBar setBarTintColor:[UIColor whiteColor]];
- }
- self.view.backgroundColor = HexRGB(0xf6f8f9);
- }
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return UIStatusBarStyleDefault;
- }
- #pragma mark - UIGestureRecognizerDelegate
- - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
- if (self.viewControllers.count <= 1) {
- return NO;
- }
- return YES;
- }
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- return YES;
- }
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- if ([self.viewControllers indexOfObject:self] == 0) {
- return YES;
- }
- return [gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]];
- }
- #pragma mark - Super class
- - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
- if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
- self.interactivePopGestureRecognizer.enabled = NO;
- }
- //如果现在push的不是栈顶控制器,那么久隐藏tabbar工具条
- if (self.childViewControllers.count >= 1) {
- viewController.hidesBottomBarWhenPushed = YES;
- }
- [super pushViewController:viewController animated:animated];
- }
- - (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
- self.visibleViewController.is_poppingToRoot = YES;
- if (self.viewControllers.count > 1) {
- self.topViewController.hidesBottomBarWhenPushed = NO;
- }
- NSArray<__kindof UIViewController *> *viewControllers = [super popToRootViewControllerAnimated:animated];
- // self.viewControllers has two items here on iOS14
- return viewControllers;
- }
- #pragma mark - UINavigationControllerDelegate
- - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
- if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)] && ![viewController isKindOfClass:NSClassFromString(@"KSBaseWKWebViewController")] && ![viewController isKindOfClass:NSClassFromString(@"FirstSettingViewController")] && ![viewController isKindOfClass:NSClassFromString(@"TXLiveRoomViewController")] && ![viewController isKindOfClass:NSClassFromString(@"TXClassroomViewController")] && ![viewController isKindOfClass:NSClassFromString(@"KSAccompanyDraftViewController")] && ![viewController isKindOfClass:NSClassFromString(@"KSDraftMergeViewController")] && ![viewController isKindOfClass:NSClassFromString(@"CloudBaseViewController")]) {
- self.interactivePopGestureRecognizer.enabled = YES;
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|