123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #import "CustomNavViewController.h"
- #import "UIImage+Color.h"
- @interface CustomNavViewController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>
- @end
- @implementation CustomNavViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- 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;
-
- appearance.shadowImage = [UIImage imageWithColor:[UIColor clearColor]];
- appearance.backgroundColor = HexRGB(0xf6f8f9);
- [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:HexRGB(0xf6f8f9)];
- }
- 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;
- }
-
- if (self.childViewControllers.count >= 1) {
- viewController.hidesBottomBarWhenPushed = YES;
- }
- [super pushViewController:viewController animated:animated];
- }
- - (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
- if (self.viewControllers.count > 1) {
- self.topViewController.hidesBottomBarWhenPushed = NO;
- }
- NSArray<__kindof UIViewController *> *viewControllers = [super popToRootViewControllerAnimated:animated];
-
- 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")]) {
- self.interactivePopGestureRecognizer.enabled = YES;
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- @end
|