原生函数:
//通过View获取当前的ViewController
- (UIViewController *)currentViewControllerForVC:(UIView *)view
{
Class vcClass = [UIViewController class];
UIResponder *responder = view;
while ((responder = [responder nextResponder]))
if ([responder isKindOfClass:vcClass])
return (UIViewController *)responder;
return nil;
}
转换结果:
function currentVCForView(view) {
var vcClass = UIViewController.class
var responder = view
while (responder = responder. nextResponder) {
var isVCType = objc_msgSend(responder, "isKindOfClass:", vcClass)
if (isVCType) {
return responder
}
}
return nil
}
最主要的技术点是通过objc_msgSend(receiver, selector, arg1, arg2, …);
转换带参数的OC方法。