从我的问题来看:没有子类化 UIView 或 UIViewController:如果添加了子视图,是否可以捕获?
我想知道如何将代码从答案移植到 MonoTouch。它基本上是用一个新方法替换一个方法,然后在没有子类化的情况下调用旧方法。是否有可能让这个指针在 MonoTouch 中工作?
//Makes views announce their change of superviews
Method method = class_getInstanceMethod([UIView class], @selector(willMoveToSuperview:));
IMP originalImp = method_getImplementation(method);
void (^block)(id, UIView*) = ^(id _self, UIView* superview) {
[_self willChangeValueForKey:@"superview"];
originalImp(_self, @selector(willMoveToSuperview:), superview);
[_self didChangeValueForKey:@"superview"];
};
IMP newImp = imp_implementationWithBlock((__bridge void*)block);
method_setImplementation(method, newImp);