Created
September 12, 2020 15:44
-
-
Save chbeer/5a4506d6e657c3b3ea3fdfd0391c9028 to your computer and use it in GitHub Desktop.
Prevent PDFView from stealing first responder when setting document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
SwizzlePDFDocumentView() | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SwizzleHelper.h" | |
// found here: https://github.com/defagos/CoconutKit/blob/master/Framework/Sources/Core/HLSRuntime.h | |
#import "HLSRuntime.h" | |
#import <UIKit/UIKit.h> | |
#import <PDFKit/PDFKit.h> | |
static BOOL (*s_becomeFirstResponder)(id, SEL) = NULL; | |
static BOOL swizzle_becomeFirstResponder(id self, SEL _cmd) | |
{ | |
if ([self isKindOfClass:NSClassFromString(@"PDFDocumentView")]) { | |
return NO; | |
} | |
return s_becomeFirstResponder(self, _cmd); | |
} | |
void SwizzlePDFDocumentView() { | |
HLSSwizzleSelector([UIResponder class], @selector(becomeFirstResponder), swizzle_becomeFirstResponder, &s_becomeFirstResponder); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment