forked from QMUI/QMUIDemo_iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboardViewController.m
More file actions
103 lines (79 loc) · 3.57 KB
/
Copy pathKeyboardViewController.m
File metadata and controls
103 lines (79 loc) · 3.57 KB
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
95
96
97
98
99
100
101
102
103
//
// KeyboardViewController.m
// QMUIKeyboard
//
// Created by MoLice on 2021/A/31.
// Copyright © 2021 QMUI Team. All rights reserved.
//
#import "KeyboardViewController.h"
#import "Common.h"
@interface KeyboardViewController ()
@property (nonatomic, strong) UIButton *nextKeyboardButton;
@property(nonatomic, strong) UILabel *countLabel;
@end
@implementation KeyboardViewController
static NSInteger count = 0;
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
OverrideImplementation([UIImage class], @selector(initWithCoder:), ^id(__unsafe_unretained Class originClass, SEL originCMD, IMP (^originalIMPProvider)(void)) {
return ^UIImage *(UIImage *selfObject, NSCoder *firstArgv) {
// call super
UIImage * (*originSelectorIMP)(id, SEL, NSCoder *);
originSelectorIMP = (UIImage * (*)(id, SEL, NSCoder *))originalIMPProvider();
UIImage * result = originSelectorIMP(selfObject, originCMD, firstArgv);
NSLog(@"-[UIImage initWithCoder:], %@", result);
count++;
return result;
};
});
});
}
- (void)updateViewConstraints {
[super updateViewConstraints];
// Add custom view sizing constraints here
}
- (void)viewDidLoad {
[super viewDidLoad];
// Perform custom UI setup here
self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.nextKeyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];
[self.view addSubview:self.nextKeyboardButton];
[self.nextKeyboardButton.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;
[self.nextKeyboardButton.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
self.countLabel = UILabel.new;
self.countLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:.8];
self.countLabel.font = [UIFont fontWithName:@"Menlo" size:16];
self.countLabel.textAlignment = NSTextAlignmentCenter;
self.countLabel.numberOfLines = 0;
[self.view addSubview:self.countLabel];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.countLabel.text = [NSString stringWithFormat:@"-[UIImage initWithCoder:]\n%@次", @(count)];
[self.view setNeedsLayout];
}
- (void)viewWillLayoutSubviews
{
self.nextKeyboardButton.hidden = !self.needsInputModeSwitchKey;
[super viewWillLayoutSubviews];
[self.countLabel sizeToFit];
self.countLabel.center = CGPointMake(CGRectGetWidth(self.view.bounds) / 2, CGRectGetHeight(self.view.bounds) / 2);
}
- (void)textWillChange:(id<UITextInput>)textInput {
// The app is about to change the document's contents. Perform any preparation here.
}
- (void)textDidChange:(id<UITextInput>)textInput {
// The app has just changed the document's contents, the document context has been updated.
UIColor *textColor = nil;
if (self.textDocumentProxy.keyboardAppearance == UIKeyboardAppearanceDark) {
textColor = [UIColor whiteColor];
} else {
textColor = [UIColor blackColor];
}
[self.nextKeyboardButton setTitleColor:textColor forState:UIControlStateNormal];
}
@end