cari

Rumah  >  Soal Jawab  >  teks badan

objective-c - 请问如何禁用当前控制器的侧边右滑pop手势?当前VC是push过来的

如题:我的跟控制器是是个导航控制器,现在有一个A控制器是我push过来的,我希望这个控制器只能点击导航条左边的返回按钮来pop,而侧边右滑动的手势pop我希望能把它禁用掉。当然其他控制器我希望不还是有这个pop的手势。请问我改如何实现呢?

習慣沉默習慣沉默2757 hari yang lalu564

membalas semua(2)saya akan balas

  • 高洛峰

    高洛峰2017-05-02 09:31:05

    Tulis dalam pengawal A:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    
        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
    
    // 给该控制器添加协议 <UIGestureRecognizerDelegate>
    
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
    {
        return gestureRecognizer != self.navigationController.interactivePopGestureRecognizer;
    }
    

    balas
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-02 09:31:05

    Bangunan dari A -> B lebih elegan

    Di dalam viewDidLoad B

    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
        [super pushViewController:viewController animated:animated];
        self.interactivePopGestureRecognizer.enabled = NO;
    }

    Kemudian dalam viewDidDisappear

    self.navigationController.interactivePopGestureRecognizer.enabled = YES;

    Semuanya ditulis dalam B, bukankah lebih elegan?

    balas
    0
  • Batalbalas