Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setViewControllers:animated:侧滑设置没生效 #195

Open
lonely4flow opened this issue Jul 27, 2019 · 0 comments
Open

setViewControllers:animated:侧滑设置没生效 #195

lonely4flow opened this issue Jul 27, 2019 · 0 comments

Comments

@lonely4flow
Copy link

在使用setViewControllers:animated:方法一次性push多个Controller到栈里时,某个Controller设置的禁止侧滑功能没有生效,需要对setViewControllers:animated:要像pushViewController:animated:一样支持,添加方法如下:

  • (void)load
    {
    // Inject "-setViewControllers:animated:"
    Method originalMethod = class_getInstanceMethod(self, @selector(pushViewController:animated:));
    Method swizzledMethod = class_getInstanceMethod(self, @selector(fd_pushViewController:animated:));
    method_exchangeImplementations(originalMethod, swizzledMethod);
    // Inject "-pushViewController:animated:"
    Method originalMethod2 = class_getInstanceMethod(self, @selector(setViewControllers:animated:));
    Method swizzledMethod2 = class_getInstanceMethod(self, @selector(fd_setViewControllers:animated:));
    method_exchangeImplementations(originalMethod2, swizzledMethod2);
    }
  • (void)fd_setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
    {
    for(UIViewController *viewController in viewControllers){
    if (![self.interactivePopGestureRecognizer.view.gestureRecognizers containsObject:self.fd_fullscreenPopGestureRecognizer]) {

          // Add our own gesture recognizer to where the onboard screen edge pan gesture recognizer is attached to.
          [self.interactivePopGestureRecognizer.view addGestureRecognizer:self.fd_fullscreenPopGestureRecognizer];
          
          // Forward the gesture events to the private handler of the onboard gesture recognizer.
          NSArray *internalTargets = [self.interactivePopGestureRecognizer valueForKey:@"targets"];
          id internalTarget = [internalTargets.firstObject valueForKey:@"target"];
          SEL internalAction = NSSelectorFromString(@"handleNavigationTransition:");
          self.fd_fullscreenPopGestureRecognizer.delegate = self.fd_popGestureRecognizerDelegate;
          [self.fd_fullscreenPopGestureRecognizer addTarget:internalTarget action:internalAction];
          
          // Disable the onboard gesture recognizer.
          self.interactivePopGestureRecognizer.enabled = NO;
      }
      [self fd_setupViewControllerBasedNavigationBarAppearanceIfNeeded:viewController];
    

    }
    [self fd_setViewControllers:viewControllers animated:animated];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant