From 3e5c40fe900780502e31ed38601bd78b935808f3 Mon Sep 17 00:00:00 2001 From: jian <1799974611@qq.com> Date: Fri, 27 Nov 2015 23:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=96=B9=E6=B3=95=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E6=8A=BD=E5=8F=96=E5=88=B0=E4=B8=80=E4=B8=AA=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E9=87=8C=EF=BC=9Afd=5FmethodSwizzling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...igationController+FDFullscreenPopGesture.m | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m b/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m index 914f217..36f6514 100644 --- a/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m +++ b/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m @@ -23,6 +23,18 @@ #import "UINavigationController+FDFullscreenPopGesture.h" #import +static void fd_methodSwizzling(Class class, SEL originalSelector, SEL swizzledSelector) { + Method originalMethod = class_getInstanceMethod(class, originalSelector); + Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); + + BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); + if (success) { + class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); + } else { + method_exchangeImplementations(originalMethod, swizzledMethod); + } +} + @interface _FDFullscreenPopGestureRecognizerDelegate : NSObject @property (nonatomic, weak) UINavigationController *navigationController; @@ -86,15 +98,7 @@ + (void)load SEL originalSelector = @selector(viewWillAppear:); SEL swizzledSelector = @selector(fd_viewWillAppear:); - Method originalMethod = class_getInstanceMethod(class, originalSelector); - Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); - - BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); - if (success) { - class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); - } else { - method_exchangeImplementations(originalMethod, swizzledMethod); - } + fd_methodSwizzling(class, originalSelector, swizzledSelector); }); } @@ -132,15 +136,7 @@ + (void)load SEL originalSelector = @selector(pushViewController:animated:); SEL swizzledSelector = @selector(fd_pushViewController:animated:); - Method originalMethod = class_getInstanceMethod(class, originalSelector); - Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); - - BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); - if (success) { - class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); - } else { - method_exchangeImplementations(originalMethod, swizzledMethod); - } + fd_methodSwizzling(class, originalSelector, swizzledSelector); }); }