美文网首页iOS开发
监听UINavigationController 滑动返回手势

监听UINavigationController 滑动返回手势

作者: 酷哥不回头看爆炸 | 来源:发表于2017-02-16 14:03 被阅读466次

    1、添加代理 UINavigationControllerDelegate

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [self.navigationController.navigationBar setHidden:YES];
        if ([[[UIDevice currentDevice] systemVersion] floatValue] > 7.0) {
            self.navigationController.delegate = self;
        }
    }
    
    - (void)viewWillDisappear:(BOOL)animated{
        if ([[[UIDevice currentDevice] systemVersion] floatValue] > 7.0) {
            self.navigationController.delegate = nil;
        }
    }
    

    2、实现代理方法

    //监听滑动手势
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
        id <UIViewControllerTransitionCoordinator>tc = navigationController.topViewController.transitionCoordinator;
        [tc notifyWhenInteractionChangesUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
            [dataKit kit].reloadFlage = [context isCancelled];
        }];
    }
    

    [context isCancelled] 是BOOL类型,未返回[context isCancelled]==YES,返回成功[context isCancelled]==NO。

    点击按钮返回 或使用 [navigationController popviewcontorller] 不进入此回调。

    相关文章

      网友评论

        本文标题:监听UINavigationController 滑动返回手势

        本文链接:https://www.haomeiwen.com/subject/iyfhwttx.html