美文网首页
iOS侧滑卡住问题

iOS侧滑卡住问题

作者: 王家小雷 | 来源:发表于2019-06-17 17:31 被阅读0次

1.在你的UINavigationController里面
.m

import "CBNavigationController.h"

@implementation CBNavigationController

  • (void)viewDidLoad
    {
    __weak CBNavigationController *weakSelf = self;

    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
    self.interactivePopGestureRecognizer.delegate = weakSelf;

      self.delegate = weakSelf;
    

    }
    }

// Hijack the push method to disable the gesture

  • (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]&&animated==YES){
    // 防止在push下一个界面动画过程中,用户左侧手势返回,手势冲突造成的crash,先将侧滑关闭
    self.interactivePopGestureRecognizer.enabled = NO;
    }

    [super pushViewController:viewController animated:animated];
    }

  • (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
    {
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]&&animated==YES){
    self.interactivePopGestureRecognizer.enabled = NO;
    }

    return [super popToRootViewControllerAnimated:animated];
    }

  • (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
    {

    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
    self.interactivePopGestureRecognizer.enabled = NO;
    }

    return [super popToViewController:viewController animated:animated];
    }

pragma mark UINavigationControllerDelegate

  • (void)navigationController:(UINavigationController *)navigationController

     didShowViewController:(UIViewController *)viewController
    
                  animated:(BOOL)animate
    

{

// Enable the gesture again once the new controller is shown
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
    // 页面加载完成后,将侧滑手势打开
    self.interactivePopGestureRecognizer.enabled = YES;
    if (self.viewControllers.count < 2 || self.visibleViewController == [self.viewControllers objectAtIndex:0]) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }

}

}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
NSLog(@"123");

if (gestureRecognizer==self.interactivePopGestureRecognizer) {
    
    if (self.viewControllers.count < 2 || self.visibleViewController == [self.viewControllers objectAtIndex:0]) {
        return NO;
    }
}
return YES;

}
@end

相关文章

网友评论

      本文标题:iOS侧滑卡住问题

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