iOS笔记之_侧滑返回

方法一:

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使其支持侧滑返回

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容