#import "UIViewController+MethodSwizzling.h"
#import <objc/runtime.h>
@implementation UIViewController (MethodSwizzling)
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
{
Method originMethod = class_getInstanceMethod([self class], @selector(viewDidAppear:));
Method swizzledMethod = class_getInstanceMethod([self class], @selector(swizzling_viewDidAppear:));
method_exchangeImplementations(originMethod, swizzledMethod);
}
});
}
- (void)swizzling_viewDidAppear:(BOOL)animated
{
[self swizzling_viewDidAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
#import "UINavigationController+MethodSwizzling.h"
#import <objc/runtime.h>
@implementation UINavigationController (MethodSwizzling)
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
{
Method originMethod = class_getInstanceMethod([self class], @selector(pushViewController:animated:));
Method swizzledMethod = class_getInstanceMethod([self class], @selector(swizzling_pushViewController:animated:));
method_exchangeImplementations(originMethod, swizzledMethod);
}
});
}
- (void)swizzling_pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
self.interactivePopGestureRecognizer.enabled = NO;
[self swizzling_pushViewController:viewController animated:animated];
}
@end
本文介绍了一种在iOS应用中使用Objective-C运行时的方法交换技术,通过该技术可以在不影响原有功能的前提下,修改或增强UIViewController和UINavigationController的行为。
999

被折叠的 条评论
为什么被折叠?



