static IMP originIMP;
static id replacedMethod(id self,SEL _cmd, id view1, NSLayoutAttribute attr1,NSLayoutRelation relation,id view2,NSLayoutAttribute attr2
,CGFloat multiplier,CGFloat c)
{
// NSAssert(multiplier != 0, @"error !!!1multiplier is 0");
NSLog(@"constraintWithItem:%@",self);
if (multiplier == 0) {
NSLog(@"error !!!1multiplier is 0");
}
id result = ((id(*)(id,SEL, id, NSLayoutAttribute,NSLayoutRelation,id,NSLayoutAttribute
,CGFloat,CGFloat))originIMP)(self,_cmd,view1,attr1,relation,view2,attr2,multiplier,c);
return result;
}
+(instancetype)replacedConstraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c
{
// NSAssert(multiplier != 0, @"error !!!1multiplier is 0");
NSLog(@"replacedConstraintWithItem:%@,multiplier:%f,attr1:%d,view2:%@",view1,multiplier,(int)attr1,view2);
if (multiplier == 0&&NSLayoutAttributeWidth!=attr1&&NSLayoutAttributeHeight!=attr1) {
NSLog(@"error !!!1multiplier is 0");
}
if (view2 == nil&&NSLayoutAttributeWidth!=attr1&&NSLayoutAttributeHeight!=attr1) {
NSLog(@"view2 is nil");
}
id result = ((id(*)(id,SEL, id, NSLayoutAttribute,NSLayoutRelation,id,NSLayoutAttribute
,CGFloat,CGFloat))originIMP)(self,_cmd,view1,attr1,relation,view2,attr2,multiplier,c);
return result;
}
#ifdef DEBUG
Method oriMethod = class_getClassMethod([NSLayoutConstraint class], @selector(constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:));
originIMP = method_getImplementation(oriMethod);
// originIMP = class_replaceMethod([NSLayoutConstraint class], @selector(constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:), (IMP)replacedMethod, method_getTypeEncoding(method));
Method replacedMethod = class_getClassMethod([self class], @selector(replacedConstraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:));
method_exchangeImplementations(oriMethod, replacedMethod);
//originIMP = class_replaceMethod(objc_getMetaClass("NSLayoutConstraint"), @selector(constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:), (IMP)replacedMethod, method_getTypeEncoding(oriMethod));
#endif