Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2010 19:21
Show Gist options
  • Save anonymous/634867 to your computer and use it in GitHub Desktop.
Save anonymous/634867 to your computer and use it in GitHub Desktop.
#ifdef OMNI_ASSERTIONS_ON
static CGRect (*_original_convertRectFromView)(UIView *self, SEL _cmd, CGRect rect, UIView *view) = NULL;
static CGRect (*_original_convertRectToView)(UIView *self, SEL _cmd, CGRect rect, UIView *view) = NULL;
static CGPoint (*_original_convertPointFromView)(UIView *self, SEL _cmd, CGPoint point, UIView *view) = NULL;
static CGPoint (*_original_convertPointToView)(UIView *self, SEL _cmd, CGPoint point, UIView *view) = NULL;
static UIView *_rootView(UIView *view)
{
while (YES) {
UIView *container = view.superview;
if (!container)
return view;
view = container;
}
}
static BOOL _viewsCompatible(UIView *view1, UIView *view2)
{
// -window on UIWindow returns nil instead of self. we really only need the two views to have a common ancestor.
UIView *root1 = _rootView(view1);
UIView *root2 = _rootView(view2);
OBASSERT(root1 == root2);
return YES;
}
static CGRect _replacement_convertRectFromView(UIView *self, SEL _cmd, CGRect rect, UIView *view)
{
OBPRECONDITION(_viewsCompatible(self, view));
return _original_convertRectFromView(self, _cmd, rect, view);
}
static CGRect _replacement_convertRectToView(UIView *self, SEL _cmd, CGRect rect, UIView *view)
{
OBPRECONDITION(_viewsCompatible(self, view));
return _original_convertRectToView(self, _cmd, rect, view);
}
static CGPoint _replacement_convertPointFromView(UIView *self, SEL _cmd, CGPoint point, UIView *view)
{
OBPRECONDITION(_viewsCompatible(self, view));
return _original_convertPointFromView(self, _cmd, point, view);
}
static CGPoint _replacement_convertPointToView(UIView *self, SEL _cmd, CGPoint point, UIView *view)
{
OBPRECONDITION(_viewsCompatible(self, view));
return _original_convertPointToView(self, _cmd, point, view);
}
static void OUIViewPerformPosing(void) __attribute__((constructor));
static void OUIViewPerformPosing(void)
{
Class viewClass = NSClassFromString(@"UIView");
_original_convertRectFromView = (typeof(_original_convertRectFromView))OBReplaceMethodImplementation(viewClass, @selector(convertRect:fromView:), (IMP)_replacement_convertRectFromView);
_original_convertRectToView = (typeof(_original_convertRectToView))OBReplaceMethodImplementation(viewClass, @selector(convertRect:toView:), (IMP)_replacement_convertRectToView);
_original_convertPointFromView = (typeof(_original_convertPointFromView))OBReplaceMethodImplementation(viewClass, @selector(convertPoint:fromView:), (IMP)_replacement_convertPointFromView);
_original_convertPointToView = (typeof(_original_convertPointToView))OBReplaceMethodImplementation(viewClass, @selector(convertPoint:toView:), (IMP)_replacement_convertPointToView);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment