zoukankan      html  css  js  c++  java
  • 关于 ios 7.0启用的UINavgationViewController的interactivePopGestureRecognizer手势

    相信所有试着使用自定义返回的leftItem,但是也会发现一个问题就是ios7.0的那个pan返回上一页的手势失效了。

    因为自己使用app的时候是7.0的系统,所以呢,觉得相当的不爽,于是纠结了,然后到stackoverflow.com里面找到相关的资料,但是各种try,各种bug,最后,综合所有的方法。

    嗯,好吧,最后还是采用网上的一个放,继承UINavgationViewController,然后派生对应方法。

    于是,使用这个代码在你的工程里就OK,暂时未发现BUG。标记:

      CBNavigationController.h

    #import <UIKit/UIKit.h>

     

    @interface CBNavigationController : UINavigationController <UINavigationControllerDelegate, UIGestureRecognizerDelegate>

    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;

    - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;

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

     

    @end

     

    #import "CBNavigationController.h"

     

     

       CBNavigationController.m

    @implementation CBNavigationController

     

    - (void)viewDidLoad

    {

        __weakCBNavigationController *weakSelf = self;

        

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

        {

            self.interactivePopGestureRecognizer.delegate = weakSelf;

            self.delegate = weakSelf;

        }

    }

     

    // Hijack the push method to disable the gesture

     

    - (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  [superpopToRootViewControllerAnimated: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

    {

        // Enable the gesture again once the new controller is shown

        

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

            self.interactivePopGestureRecognizer.enabled = YES;

        }

    }

     

     

    -(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

    {

        if (gestureRecognizer==self.interactivePopGestureRecognizer) {

            if (self.viewControllers.count<2||self.visibleViewController==[self.viewControllersobjectAtIndex:0]) {

                return NO;

            }

        }

        returnYES;

    }

     

    @end

     

     

  • 相关阅读:
    第六十篇、音视频采集硬编码(H264+ACC)
    第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法
    第五十九篇、OC录制小视频
    第五十八篇、iOS 微信聊天发送小视频的秘密
    第五十七篇、AVAssetReader和AVAssetWrite 对视频进行编码
    第五十六篇、OC打开本地和网络上的word、ppt、excel、text等文件
    Objective-C 编码建议
    在block中使用self
    纯代码TableView自适应高度(很老的使用方法)
    iOS应用架构谈 网络层设计方案
  • 原文地址:https://www.cnblogs.com/lingzhiguiji/p/3646028.html
Copyright © 2011-2022 走看看