zoukankan      html  css  js  c++  java
  • ios侧滑返回:完美解决 interactivePopGestureRecognizer 卡住的问题

    interactivePopGestureRecognizer是iOS7推出的解决VeiwController滑动后退的新功能,虽然很实用,但是坑也很多啊(比如在rootViewcontroller下,使用侧滑返回手势,可能就卡住了),这里给出如何完美解决interactivePopGestureRecognizer卡住的问题.

    当然我们要自定义UINavigationController来解决这个问题:

    #import "MMNavController.h"
    
    
    @interface MMNavController ()
    {
        
    }
    
    @end
    
    @implementation MMNavController
    
    - (id)initWithRootViewController:(UIViewController *)rootViewController
    {
        self = [super initWithRootViewController:rootViewController];
        if (self) {
            // Custom initialization
            
        }
        return self;
    }
    
    
    - (void)viewDidLoad
    {
        
        __weak MMNavController *weakSelf = self;
        
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
        {
            self.interactivePopGestureRecognizer.delegate = weakSelf;
            
            self.delegate = weakSelf;
        }
        
    }
    
    - (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  [super popToRootViewControllerAnimated: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
    {
        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.viewControllers objectAtIndex:0] )
            {
                return NO;
            }
        }
        
        return YES;
    }
    
    
    @end

    转载自:http://adad184.com/2013/12/12/2013-12-12-wan-mei-jie-jue-interactivepopgesturerecognizer-qia-zhu-de-wen-ti/

  • 相关阅读:
    使用 lntelliJ IDEA 创建 Maven 工程的springboot项目
    HTTP协议小记
    TCP/UDP的网络底层实现
    TCP的三次握手和四次挥手
    IP地址和MAC地址绑定的必要性
    什么是回调函数?
    基于TCP实现的Socket通讯详解
    HTTP协议随笔
    计算机虚拟世界的入门常识(1)——信号的原理
    UDP比TCP好用的优势
  • 原文地址:https://www.cnblogs.com/benbenzhu/p/4365292.html
Copyright © 2011-2022 走看看