Method srcMethod = class_getInstanceMethod(srcClass, srcSel);
Method swizzledMethod = class_getInstanceMethod(srcClass, swizzledSel);
if (!srcClass || !srcMethod || !swizzledMethod) return;
//Add a layer of protection measures. If the method is added successfully, it means that the method does not exist in this class, but exists in the parent class, and the method of the parent class cannot be exchanged, otherwise the method will crash when the parent class object calls the method; Adding failure indicates that the method exists in this class
BOOL addMethod = class_addMethod(srcClass, srcSel, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (addMethod){
//After the IMP is successfully implemented by adding methods, the original implementation will be replaced with the swizzledMethod method to achieve method exchange without affecting the implementation of the parent method
class_replaceMethod(srcClass, swizzledSel, method_getImplementation(srcMethod), method_getTypeEncoding(srcMethod));
}else{
//Adding failed, calling the implementation of the two interactive methods
method_exchangeImplementations(srcMethod, swizzledMethod);
}
1条答案
按热度按时间cotxawn71#
//IQKeyBoardManager Issues暴力事件已解决,三方数据库和系统出现问题
import“用户界面视图控制器+当前KBHook. h”
@实现UIView控制器(当前KBIook)
}
}
//交换两个对象方法的实现
}
@结束