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/

  • 相关阅读:
    小程序的媒体组件
    微信小程序开发系列之Hello World
    centos 6 mysql 5.6 源码安装
    php 源码安装
    centos7 源码安装nginx
    CentOS 7.2部署MariaDB Galera Cluster(10.1.21-MariaDB) 3主集群环境
    MySQL读写分离
    MySQL主从复制(Master-Slave)实践
    lvs+keepalived+nginx负载均衡搭建
    Kubernetes在CentOS7下二进制文件方式安装、离线安装
  • 原文地址:https://www.cnblogs.com/benbenzhu/p/4365292.html
Copyright © 2011-2022 走看看