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

     

     

  • 相关阅读:
    C#与数据库访问技术总结(十一)之数据阅读器(DataReader)1
    C#与数据库访问技术总结(十)之添加&删除
    C#与数据库访问技术总结(九)之实例
    C#与数据库访问技术总结(八)之ExecuteNonQuery方法
    C#与数据库访问技术总结(六)之Command对象创建SQl语句代码示例
    C#与数据库访问技术总结(七)综合示例
    C#与数据库访问技术总结(五)之Command对象的常用方法
    OS——进程简答题(1)
    LAMP/LNMP 一键安装脚本
    运维如何延续自己的职业生涯--萧田国2017年GOPS深圳站演讲内容
  • 原文地址:https://www.cnblogs.com/lingzhiguiji/p/3646028.html
Copyright © 2011-2022 走看看