iOS 记录navigationController的全屏滑动

看到@J_雨大牛的博客,讲的很细致,在此记录下第二种方法,以备以后使用,原文链接:http://www.jianshu.com/p/d39f7d22db6c

#import "Nav.h"

@interface Nav ()<UIGestureRecognizerDelegate>

@end

@implementation Nav

- (void)viewDidLoad {
    [super viewDidLoad];
    
          //拿到navigationController原有的pop手势
    UIGestureRecognizer *gesture = self.interactivePopGestureRecognizer;
        //将自有手势停用
    gesture.enabled = NO;
        //拿到手势的view
    UIView *gestureView = gesture.view;
    
        //创建一个自己的手势
    UIPanGestureRecognizer *popRecognizer = [[UIPanGestureRecognizer alloc] init];
    popRecognizer.delegate = self;
    popRecognizer.maximumNumberOfTouches = 1;
      //将自己创建的手势放到原有手势的view上
    [gestureView addGestureRecognizer:popRecognizer];
    
        //获取系统的手势的target数组
    NSMutableArray *_targets = [gesture valueForKey:@"_targets"];
        //获取它的唯一对象 有一个叫UIGestureRecognizerTarget的私有类,有一个属性叫_target
    id gestureRecognizerTarget = [_targets firstObject];
        //获取_target:_UINavigationInteractiveTransition 有一个方法叫handleNavigationTranstion
    id navigationInteractiveTransition = [gestureRecognizerTarget valueForKey:@"_target"];
        //从控制台获取出他的方法签名
    SEL handelTransition = NSSelectorFromString(@"handleNavigationTransition:");
        //创建一个与系统一毛一样的手势 我们只把他的类改为UIPanGestureRecognizer
    [popRecognizer addTarget:navigationInteractiveTransition action:handelTransition];

}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
        //这里有两个条件不允许手势 1 当前控制器为根控制器 2 如果这个push  pop 动画正在执行(私有属性)
    return self.viewControllers.count != 1 && ![[self valueForKey:@"_isTransitioning"] boolValue];
}

使用时

#import "AppDelegate.h"
#import "Nav.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    ViewController *vc = [[ViewController alloc] init];
    Nav *nav = [[Nav alloc] initWithRootViewController:vc];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    
    return YES;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值