-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUIViewController+FixUIInputAccessoryView.m
94 lines (72 loc) · 2.76 KB
/
UIViewController+FixUIInputAccessoryView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// UIViewController+FixUIInputAccessoryView.m
// UIKitKeyboard
//
// Created by Aleksei Savelev on 12/04/2021
//
#import "UIInputAccessoryView.h"
#import "UIInputAccessoryView+ListenTextField.h"
#import "UIViewController+FixUIInputAccessoryView.h"
#import <objc/runtime.h>
@implementation UIViewController (FixUIInputAccessoryView)
+ (void)load
{
if ([self instancesRespondToSelector:@selector(transitionCoordinator)]) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self uikit_swizzleSelector:@selector(beginAppearanceTransition:animated:) withSelector:@selector(uikit_beginAppearanceTransition:animated:)];
[self uikit_swizzleSelector:@selector(viewDidAppear:) withSelector:@selector(uikit_viewDidAppear)];
[self uikit_swizzleSelector:@selector(viewDidDisappear:) withSelector:@selector(uikit_viewDidDisappear)];
});
}
}
+ (void)uikit_swizzleSelector:(SEL)originalSelector withSelector:(SEL)swizzledSelector
{
Class class = [self class];
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
- (void)uikit_beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated
{
[self uikit_beginAppearanceTransition:isAppearing animated:animated];
if (isAppearing || !animated) {
return;
}
if (![self.transitionCoordinator isInteractive]) {
return;
}
UIInputAccessoryView *currentAccessoryView = [UIInputAccessoryView currentView];
if (currentAccessoryView == nil) {
return;
}
currentAccessoryView.isInAppearanceTransition = YES;
}
/**
* Need to reset a flag if appearance transtion is ended
*/
- (void)uikit_viewDidAppear {
[self uikit_viewDidAppear];
UIInputAccessoryView *currentAccessoryView = [UIInputAccessoryView currentView];
if (currentAccessoryView == nil) {
return;
}
currentAccessoryView.isInAppearanceTransition = NO;
}
/**
* Need to reset a flag if appearance transtion is ended
*/
- (void)uikit_viewDidDisappear {
[self uikit_viewDidDisappear];
UIInputAccessoryView *currentAccessoryView = [UIInputAccessoryView currentView];
if (currentAccessoryView == nil) {
return;
}
currentAccessoryView.isInAppearanceTransition = NO;
}
@end