ios码皇之路之 iOS

快速实现全屏滑动返回

2016-02-19  本文已影响214人  德蒙_托尔斯泰

需求:当页面跳转的时候, 能够全屏滑动返回

全屏滑动.gif

怎么能够实现全屏滑动, 下面一步步分析

/** push时,设置leftBtnItem*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//    NSLog(@"%zd", self.childViewControllers.count);
    
    if (self.childViewControllers.count > 0) {
        
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithRenderingOriginalName:@"NavBack"] style:UIBarButtonItemStylePlain target:self action:@selector(popBack)];
        
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}
设置back按钮后.gif 代理置nil.gif
//判断当前显示的控制器为根控制器时,就启用系统的代理,否则,不启用
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//    NSLog(@"%@", viewController);
    if (viewController == self.childViewControllers[0]) {
        self.interactivePopGestureRecognizer.delegate = self.interactivePopGesDelegate;
    }else{
        self.interactivePopGestureRecognizer.delegate = nil;
    }
}
解决假死 bug

]

处理全屏滑动返回

 id target = self.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
//    JJLOG(@"%@", self.interactivePopGestureRecognizer);
    self.interactivePopGestureRecognizer.enabled = NO;
    pan.delegate =self;
    [self.view addGestureRecognizer:pan];
上一篇下一篇

猜你喜欢

热点阅读