iOS笔记之_侧滑返回

2016-08-12  本文已影响228人  sunny_轻芒

方法一:

iOS 侧滑返回功能,自定义手势触发系统的pop动画。handleNavigationTransition:为系统私有API,系统自带的侧滑手势触发的回调,并且可以从页面任意地方滑动。

#import "ViewController.h"
@interface ViewController ()<UIGestureRecognizerDelegate>

@end
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];

    id target = self.navigationController.interactivePopGestureRecognizer.delegate;

    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    panGesture.delegate = self; // 设置手势代理,拦截手势触发
    [self.view addGestureRecognizer:panGesture];

    // 禁止系统自带的滑动手势
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 当前控制器是根控制器时不触发手势
    if(self.navigationController.childViewControllers.count == 1)
    {
        return NO;
    }

   return YES;
}


@end

方法二:

使用系统自带的侧滑:从边缘滑动。

self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
就酱...

参考

iOS使其支持侧滑返回

上一篇下一篇

猜你喜欢

热点阅读