0

我们可以很容易地挂钩下面的方法,CydiaSubstrate但我想知道如何卸载挂钩并将实现恢复为原始实现?谢谢!

static IMP original_UIView_setFrame_;
void replaced_UIView_setFrame_(UIView* self, SEL _cmd, CGRect frame) {  // Note the implicit self and _cmd parameters are needed explicitly here.
  CGRect originalFrame = self.frame;
  NSLog("Changing frame of %p from %@ to %@", self, NSStringFromCGRect(originalFrame), NSStringFromCGRect(frame));
  original_UIView_setFrame_(self, _cmd, frame);    // Remember to pass self and _cmd.
}
...
MSHookMessageEx([UIView class], @selector(setFrame:), (IMP)replaced_UIView_setFrame_, (IMP *)&original_UIView_setFrame_);
4

1 回答 1

1

您只需要再次交换实现,即只需再次调用以下命令:

MSHookMessageEx([UIView class], @selector(setFrame:), (IMP)replaced_UIView_setFrame_, (IMP *)&original_UIView_setFrame_);

当您交换实现时,您正在交换它们,因此通过再次交换它们,您可以回到原始状态。

于 2015-02-11T12:04:55.530 回答