123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- //
- // MyUINavigationController.m
- // jiaPeiC
- //
- // Created by Echopentakill on 16/12/13.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "MyUINavigationController.h"
- @interface MyUINavigationController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate>
- @end
- @implementation MyUINavigationController
- - (void)viewDidLoad {
- [super viewDidLoad];
- __weak MyUINavigationController *weakSelf = self;
-
- if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
- {
- self.interactivePopGestureRecognizer.delegate = weakSelf;
- self.delegate = weakSelf;
- }
- }
- //在转场/过渡的时候禁用 interactivePopGestureRecognizer当用户在转场的时候触发一个后退手势,则各种事件又凑一块了.导航栈内又成了混乱的.我的解决办法是,转场效果的过程中禁用手势识别,当新的视图控制器加载完成后再启用.再次建议使用UINavigationController的子类操作
- -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
- {
- if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
- self.interactivePopGestureRecognizer.enabled = NO;
-
- if (self.viewControllers.count) {
-
- viewController.hidesBottomBarWhenPushed = YES;
-
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnAction)];
- [backBbi setTintColor:COLOR_THEME];
- [viewController.navigationItem setLeftBarButtonItem:backBbi];
- }
-
- [super pushViewController:viewController animated:animated];
- }
- -(void)backBtnAction{
-
- [self popViewControllerAnimated:YES];
- }
- #pragma mark UINavigationControllerDelegate
- - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
- {
- // Enable the gesture again once the new controller is shown
-
-
- if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
- self.interactivePopGestureRecognizer.enabled = YES;
- }
- //
- //解决左滑手势冲突和不灵敏的问题
- -(UIViewController *)popViewControllerAnimated:(BOOL)animated {
-
- return [super popViewControllerAnimated:YES];
- }
- #pragma mark UIGestureRecognizerDelegate
- - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
- if ([self.childViewControllers count] == 1) {
- return NO;
- }
- return YES;
- }
- // 我们差不多能猜到是因为手势冲突导致的,那我们就先让 ViewController 同时接受多个手势吧
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
- return YES;
- }
- //运行试一试,两个问题同时解决,不过又发现了新问题,手指在滑动的时候,被 pop 的 ViewController 中的 UIScrollView 会跟着一起滚动,这个效果看起来就很怪(知乎日报现在就是这样的效果),而且也不是原始的滑动返回应有的效果,那么就让我们继续用代码来解决吧
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
- {
- return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|