关于 ios 7.0启用的UINavgationViewController的interactivePopGestureRecognizer手势

转载自:  http://www.cnblogs.com/lingzhiguiji/p/3646028.html

相信所有试着使用自定义返回的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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值