zoukankan      html  css  js  c++  java
  • iOS UI进阶-6.0 手势

    给每个页面添加手势,只需要统一设置不是根控制器的页面,都增加手势。需要自定义导航控制器

    1.继承代理

    @interface BSNavigationController ()<UIGestureRecognizerDelegate>
    

     2.设置代理

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        // 设置pop手势代理
        self.interactivePopGestureRecognizer.delegate = self;
        
    }
    

     3.实现代理

    #pragma mark - <UIGestureRecognizerDelegate>
    
    /**
     *  push进来的控制器大于1个,手势有效
     */
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
        
        return self.viewControllers.count > 1;
    }

    在开发过程中,经常会用到,需要关闭某个页面的手势返回功能。

    // 禁用返回手势
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        
        // 禁用 返回手势
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
    }
    
    // 开启手势
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        
        // 开启手势
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        }
    }
    // 导航栏返回
    - (void)blackBtnClick
    {
        // 开启手势,有时只在(void)viewWillDisappear:(BOOL)animated开启,该根栏目下所有的手势都会失效
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        }
        
        [self.navigationController popToRootViewControllerAnimated:YES];
    }

    参考网站:http://blog.csdn.net/jasonblog/article/details/28282147

  • 相关阅读:
    ORACLE 数据迁移到SQL SEVER2005的问题
    sql server性能分析检测数据库阻塞语句
    经典存储过程
    sql server性能分析查询死锁的sql语句
    sql server性能分析索引使用效率评估
    discuz!X2.5不改代码即可去掉网址后面的forum.php后缀
    discuz!X2.5伪静态设置
    详解ListView
    frameset、frame和iframe的区别
    android中的Context到底该怎么用
  • 原文地址:https://www.cnblogs.com/jys509/p/5060327.html
Copyright © 2011-2022 走看看