<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 一:效果 第二篇里面寫了怎樣自定義navigation實現自定義的導航控制器左右按鈕樣式,但是當我們自己實現后,系統自帶的向右邊滑動來實現回退的功能就不能用了。 這里主要實現滑動回退功能? 。? ![](https://box.kancloud.cn/2016-01-20_569f1d98a6564.jpg) ## 二:代碼實現思路 首先 在 NYNavigationController.m中放一個popDelegate來放置要更改的手勢代理對象 ~~~ @interface NYNavigationController ()<UINavigationControllerDelegate> @property (nonatomic, strong) id popDelegate; @end ~~~ 重寫 UINavigationControllerDelegate 的方法`- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated` viewDidLoad中設置代理方法,并且預先設置手勢代理用來還原 ~~~ - (void)viewDidLoad { [super viewDidLoad]; //記住手勢代理 用來還原 _popDelegate = self.interactivePopGestureRecognizer.delegate; self.delegate = self; } ~~~ ~~~ //導航控制器跳轉完成的控制器 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if (viewController == self.viewControllers[0]) { // 是根控制器 //還原手勢代理 self.interactivePopGestureRecognizer.delegate = _popDelegate; }else{ // 非根控制器 //設置手勢代理為空,就可以實現滑動了 //實現滑動返回功能 //清空滑動返回手勢的代理,就能實現滑動返回功能了。 self.interactivePopGestureRecognizer.delegate = nil; } } ~~~ ## 三: 全部navigationController的代碼 內部包括設置左右按鈕等等功能 ~~~ // // NYNavigationController.m // 貓貓微博 // // Created by apple on 15-7-29. // Copyright (c) 2015年 znycat. All rights reserved. // #import "NYNavigationController.h" #import "UIBarButtonItem+Item.h" @interface NYNavigationController ()<UINavigationControllerDelegate> @property (nonatomic, strong) id popDelegate; @end @implementation NYNavigationController + (void)initialize { // 獲取當前類下面的UIBarButtonItem UIBarButtonItem *item = [UIBarButtonItem appearanceWhenContainedIn:self, nil]; // 設置導航條按鈕的文字顏色 為黃色 NSMutableDictionary *titleAttr = [NSMutableDictionary dictionary]; titleAttr[NSForegroundColorAttributeName] = [UIColor orangeColor]; [item setTitleTextAttributes:titleAttr forState:UIControlStateNormal]; } - (void)viewDidLoad { [super viewDidLoad]; //記住手勢代理 用來還原 _popDelegate = self.interactivePopGestureRecognizer.delegate; self.delegate = self; } -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { [super pushViewController:viewController animated:animated]; // 設置非根控制器導航條內容 if (self.viewControllers.count != 0) { //非根控制器 //設置導航條的內容 //設置導航條左邊和右邊 //如果把導航條上的返回按鈕覆蓋了,那么就沒有了滑動返回功能 //設置左邊按鈕 viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"navigationbar_back"] highImage:[UIImage imageNamed:@"navigationbar_back_highlighted"] target:self action:@selector(backToPre) forControlEvents:UIControlEventTouchUpInside]; //設置右邊按鈕 viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"navigationbar_more"] highImage:[UIImage imageNamed:@"navigationbar_more_highlighted"] target:self action:@selector(backToRoot ) forControlEvents:UIControlEventTouchUpInside]; } } -(void)backToPre{ //返回上一個控制器 [self popViewControllerAnimated:YES]; } -(void)backToRoot{ //返回根控制器 [self popToRootViewControllerAnimated:YES]; } #pragma mark - UINavigationControllerDelegate 實現滑動回退功能 //導航控制器跳轉完成的控制器 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if (viewController == self.viewControllers[0]) { // 是根控制器 //還原手勢代理 self.interactivePopGestureRecognizer.delegate = _popDelegate; }else{ // 非根控制器 //設置手勢代理為空,就可以實現滑動了 //實現滑動返回功能 //清空滑動返回手勢的代理,就能實現滑動返回功能了。 self.interactivePopGestureRecognizer.delegate = nil; } } @end ~~~ ## 四:注意 設置手勢代理為空后必須要在該用的時候給設置回去,系統內部東西不能隨便亂改,要么會出現難以預料的bug。在跟控制器的時候不小心做了回退滑動那樣的操作會讓再次進入下一個頁面的導航控制器的右邊按鈕點擊無效,app就崩潰了。 ~~~ self.interactivePopGestureRecognizer.delegate = nil; ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看