文章很短希望对大家有帮助一下写太多了感觉都没人看~
//如果发现返回页面的左侧手势没有了,只能按"返回"才能回到上一页的话 , 只需清空手势代理方法即可!
//清空代理:#import "BaseNavigationController.h"
@interface BaseNavigationController () <UIGestureRecognizerDelegate>
@end
@implementation BaseNavigationController
+ (void)load {
UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[self class]]] ;
//只要是通过模型设置 , 都是通过富文本设置:
NSMutableDictionary *attrsDic = [NSMutableDictionary dictionary] ;
attrsDic[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20] ;
[navBar setTitleTextAttributes:attrsDic] ;
//设置背景图片:
[navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault] ;
}
/*
<UIScreenEdgePanGestureRecognizer: 0x7fb8b7613f80; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fb8b760f6d0>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fb8b7613e40>)>>
*/
- (void)viewDidLoad {
[super viewDidLoad];
//清空代理:
// self.interactivePopGestureRecognizer.delegate = self ;
// UIScreenEdgePanGestureRecognizer *edgePan = (UIScreenEdgePanGestureRecognizer *)self.interactivePopGestureRecognizer ;
// edgePan.edges = UIRectEdgeNone ;
//得hook到 UIScreenEdgePanGestureRecognizer 这个代码的action是怎么实现的!我并不知道如何实现全屏滑动 , 但是UIScreenEdgePanGestureRecognizer却知道!他的实现就是全屏滑动!
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)] ;
panGesture.delegate = self ;
[self.view addGestureRecognizer:panGesture] ;
//禁掉之前的滑动手势:
self.interactivePopGestureRecognizer.enabled = NO ;
}
#pragma mark - <UIGestureRecognizerDelegate>
//防止用户在根控制器的时候会造成假死状态:
//根控制器没有返回功能,但是手势操作🈶凌驾于逻辑之上,造成程序假死 ;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch {
if (self.childViewControllers.count > 1) {
return YES ;
} else {
return NO ;
}
}
//重写pushViewController操作;
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
//如果是非根控制器再去统一设置"返回":
if (self.childViewControllers.count > 0) {
viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithImage:[UIImage imageNamed:@"navigationButtonReturn"] andSelectedImage:[UIImage imageNamed:@"navigationButtonReturnClick"] setBackTitle:@"返回" addTarget:self action:@selector(backClick)] ;
}
[super pushViewController:viewController animated:animated] ;
}
- (void)backClick {
[self popViewControllerAnimated:YES] ;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
- 截图如下:
Pop手势代理方法.gif