zoukankan      html  css  js  c++  java
  • BaseNavigationController自定义导航栏

    #import <UIKit/UIKit.h>

     

    @interface RCDNavigationViewController : UINavigationController<UIGestureRecognizerDelegate,UINavigationControllerDelegate>

     

    @end

     

    //  .m

     

    #import "RCDNavigationViewController.h"

     

    @interface RCDNavigationViewController ()

     

    @end

     

    @implementation RCDNavigationViewController

     

    - (void)viewDidLoad {

      [super viewDidLoad];

     

      __weak RCDNavigationViewController *weakSelf = self;

     

      if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.delegate = weakSelf;

     

        self.delegate = weakSelf;

     

        self.interactivePopGestureRecognizer.enabled = YES;

      }

    }

     

    - (void)pushViewController:(UIViewController *)viewController

                      animated:(BOOL)animated {

      if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)] &&

          animated == YES) {

        self.interactivePopGestureRecognizer.enabled = NO;

      }

     

      [super pushViewController:viewController animated:animated];

    }

     

    - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated {

      if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)] &&

          animated == YES) {

        self.interactivePopGestureRecognizer.enabled = NO;

      }

     

      return [super popToRootViewControllerAnimated:animated];

    }

     

    - (NSArray *)popToViewController:(UIViewController *)viewController

                            animated:(BOOL)animated {

      if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.enabled = NO;

      }

      return [super popToViewController:viewController animated:animated];

    }

     

    #pragma mark UINavigationControllerDelegate

    - (void)navigationController:(UINavigationController *)navigationController

           didShowViewController:(UIViewController *)viewController

                        animated:(BOOL)animate {

      if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.enabled = YES;

      }

    }

    //UIGestureRecognizerDelegate

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

      if ([gestureRecognizer isEqual:self.interactivePopGestureRecognizer] &&

          self.viewControllers.count > 1 &&

          [self.visibleViewController isEqual:[self.viewControllers lastObject]]) {

        //判断当导航堆栈中存在页面,并且 可见视图 如果不是导航堆栈中的最后一个视图时,就会屏蔽掉滑动返回的手势。此设置是为了避免页面滑动返回时因动画存在延迟所导致的卡死。

        return YES;

      } else {

        return NO;

      }

    }

     

    @end

  • 相关阅读:
    Android下拉刷新-SwipeRefreshLayout,RecyclerView完全解析之下拉刷新与上拉加载SwipeRefreshLayout)
    自定义EditText实现一键删除数据
    Androidstudio 点9图报错的问题
    安卓Design包之CoordinatorLayout配合AppBarLayout,ToolBar,TabLaout的使用
    深入了解Hibernate的缓存使用
    跟大牛之间关于hibernate的一些探讨记录
    oracle第一招之神马都是浮云
    大鹏教你如何开发购物网站(里面都是满满的爱)
    JSTL&EL(程序员必看之一)
    动态网页开发
  • 原文地址:https://www.cnblogs.com/daxueshan/p/6655759.html
Copyright © 2011-2022 走看看