Skip to content

Instantly share code, notes, and snippets.

@pronebird
Created September 11, 2016 18:34
Show Gist options
  • Save pronebird/0d3c06485de50e100d1e93bcde08c94c to your computer and use it in GitHub Desktop.
Save pronebird/0d3c06485de50e100d1e93bcde08c94c to your computer and use it in GitHub Desktop.
NS_INLINE void MLSwizzleMethod(Class c, SEL original, SEL alternate) {
Method origMethod = class_getInstanceMethod(c, original);
Method newMethod = class_getInstanceMethod(c, alternate);
if(class_addMethod(c, original, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod(c, alternate, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, newMethod);
}
}
/**
* Workaround to prevent VO from accessing elements in presenting view beneath overlay.
*
* @param transitionView UIPresentationController.containerView
*/
static void *MLTransitionViewPatchIsModalAssociatedKey = &MLTransitionViewPatchIsModalAssociatedKey;
@interface UIView (MLTransitionViewAccessibilityPatch) @end
@implementation UIView (MLTransitionViewAccessibilityPatch)
+ (void)initialize {
Class cls_ = NSClassFromString([@[ @"UI", @"Transition", @"View" ] componentsJoinedByString:@""]);
if(self == cls_) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
MLSwizzleMethod(self, @selector(accessibilityViewIsModal), @selector(ml_transitionView_accessibilityViewIsModal));
});
}
}
- (void)ml_transitionView_setAccessibilityViewIsModal:(BOOL)isModal {
objc_setAssociatedObject(self, MLTransitionViewPatchIsModalAssociatedKey, @(isModal), OBJC_ASSOCIATION_COPY);
}
- (BOOL)ml_transitionView_accessibilityViewIsModal {
NSNumber *number = objc_getAssociatedObject(self, MLTransitionViewPatchIsModalAssociatedKey);
BOOL superValue = [self ml_transitionView_accessibilityViewIsModal];
return number ? [number boolValue] : superValue;
}
@end
void MLPatchTransitionViewAccessibility(UIView *transitionView, BOOL shouldBeModal) {
NSCParameterAssert(transitionView);
[transitionView ml_transitionView_setAccessibilityViewIsModal:shouldBeModal];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment