您的位置:首页 > 产品设计 > UI/UE

ios UINavigationController全局右滑返回

2018-01-26 17:05 323 查看
RightSlideBackNavigationController.h

#import <UIKit/UIKit.h>

@interface RightSlideBackNavigationController : UINavigationController

@end
RightSlideBackNavigationController.m

#import "nav.h"

@interface RightSlideBackNavigationController()<UIGestureRecognizerDelegate>

@end

@implementation RightSlideBackNavigationController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
id target = self.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
pan.delegate = self;
[self.view addGestureRecognizer:pan];
self.interactivePopGestureRecognizer.enabled = NO;
}

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
// 判断导航控制器是否只有一个子控制器,如果只有一个子控制器,肯定是根控制器
if (self.childViewControllers.count == 1) {
return NO;// 表示用户在根控制器界面,就不需要触发滑动手势,
}

CGPoint point = [gestureRecognizer translationInView:self.view];
if (point.x > 0) {//右滑
return YES;
} else {
return NO;
}
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

使用:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: