forkingdog / forkingdog/FDFullscreenPopGesture
setViewControllers:animated:侧滑设置没生效
- Dominant language
- Objective-C
- Stars
- 5.9k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
在使用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];
}
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.