zoukankan      html  css  js  c++  java
  • 第二十六篇、因为自定item(nav)而使系统右滑返回手势失效的解决方法

    @interface ViewController () <uigesturerecognizerdelegate>
    @end@implementation ViewController
    - (void)viewDidLoad {
            [super viewDidLoad];        // 自定义返回按钮
            UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
            [button setTitle:@"王俨2" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    }
     
    - (void)back:(UIButton *)button {
            [self.navigationController popViewControllerAnimated:YES];
    }
     
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];    if (self.navigationController.viewControllers.count > 1) {          // 记录系统返回手势的代理
            _delegate = self.navigationController.interactivePopGestureRecognizer.delegate;          // 设置系统返回手势的代理为当前控制器
            self.navigationController.interactivePopGestureRecognizer.delegate = self;
        }
    }
     
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];     // 设置系统返回手势的代理为我们刚进入控制器的时候记录的系统的返回手势代理
        self.navigationController.interactivePopGestureRecognizer.delegate = _delegate;
    }
    #pragma mark - UIGestureRecognizerDelegate- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {        return self.navigationController.childViewControllers.count > 1;
    }
     
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {    return self.navigationController.viewControllers.count > 1;
    }@end

    1.使用自定义nav item之后,默认的右滑返回的手势不可以使用

    2.进入控制器之前,把系统的Delegate保存起来,视图加载将要完成设置给默认的右滑手势

  • 相关阅读:
    CDH版本大数据集群下搭建的Hue详细启动步骤(图文详解)
    如何正确且成功破解跨平台数据库管理工具DbVisualizer?(图文详解)
    [转]【HTTP】Fiddler(二)
    [转]jQuery UI Dialog Modal Popup Yes No Confirm example in ASP.Net
    [转]artDialog
    [转]GridView排序——微软提供Sort
    [转]GridView中直接新增行、编辑和删除
    [转]asp.net的ajax以及json
    [转]JQuery Ajax 在asp.net中使用总结
    [转]Jquery easyui开启行编辑模式增删改操作
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/5873907.html
Copyright © 2011-2022 走看看