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

     

     

  • 相关阅读:
    永续债的会计处理
    python基于粒子群优化的投资组合优化研究
    R语言使用Metropolis- Hasting抽样算法进行逻辑回归
    R语言使用K-Means聚类可视化WiFi访问
    R语言实现拟合神经网络预测和结果可视化
    Python Monte Carlo K-Means聚类实战研究
    R语言: GARCH模型股票交易量的研究道琼斯股票市场指数
    R语言stan泊松回归Poisson regression
    R语言旅行推销员问题TSP
    在R语言和Stan中估计截断泊松分布
  • 原文地址:https://www.cnblogs.com/lingzhiguiji/p/3646028.html
Copyright © 2011-2022 走看看