Skip to content

Instantly share code, notes, and snippets.

@youngshook
Created August 2, 2014 15:13
Show Gist options
  • Save youngshook/b9897f061d7b1a037526 to your computer and use it in GitHub Desktop.
Save youngshook/b9897f061d7b1a037526 to your computer and use it in GitHub Desktop.
Custom leftBarButtonItem and interactivePopGestureRecognizer Freeze
#import <objc/runtime.h>
@implementation UINavigationController (PopGesture)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
// When swizzling a class method, use the following:
// Class class = object_getClass((id)self);
SEL originalSelector = @selector(pushViewController:animated:);
SEL swizzledSelector = @selector(xxx_pushViewController:animated:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
#pragma mark - Method Swizzling
- (void)xxx_pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(@"xxx_pushViewController: %@", self);
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = NO;
[self xxx_pushViewController:viewController animated:animated];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment