Skip to content

Commit d241089

Browse files
完善「一键黏贴」功能
1 parent d7c4a23 commit d241089

File tree

5 files changed

+62
-16
lines changed

5 files changed

+62
-16
lines changed

KBDock.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
-(id)initWithImageName:(id)arg1 identifier:(id)arg2;
88
@end
99

10-
@interface UISystemKeyboardDockController : UIViewController{
11-
UIKeyboardDockItem * _dictationDockItem;
12-
}
13-
-(void)dictationItemButtonWasPressed:(id)arg1 withEvent:(id)arg2;
14-
@end
15-
1610
@class KBDockCollectionView;
1711
@interface UIKeyboardDockView : UIView{
1812
UIKeyboardDockItem* _rightDockItem;
@@ -22,6 +16,14 @@
2216
@property (nonatomic,retain) UIKeyboardDockItem *rightDockItem;
2317
@end
2418

19+
@interface UISystemKeyboardDockController : UIViewController{
20+
UIKeyboardDockItem * _dictationDockItem;
21+
}
22+
@property (nonatomic,retain) UIKeyboardDockView * dockView;
23+
-(void)dictationItemButtonWasPressed:(id)arg1 withEvent:(id)arg2;
24+
@end
25+
26+
2527
@interface UIKeyboardMenuView : UIView
2628
-(id)tableView:(id)arg1 cellForRowAtIndexPath:(id)arg2;
2729
@end
@@ -56,3 +58,11 @@
5658
- (void)customizeCell:(id)arg1 forItemAtIndex:(unsigned long long)arg2 ;
5759
- (void)_reloadInputSwitcherItems;
5860
@end
61+
62+
63+
@interface UIPasteboard : NSObject
64+
@property (nonatomic,copy) NSArray * items;
65+
@property (nonatomic,readonly) long long numberOfItems;
66+
-(void)addItems:(id)arg1;
67+
-(void)setString:(NSString *)arg1;
68+
@end

KBDock.xm

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
#import "Manager/DLicenseManager.h"
44
#import "KBDockMacro.h"
55
#import "KBDockClipBoardViewController.h"
6+
#import <objc/runtime.h>
7+
#import "UIView+Extend.h"
68

79
#define kWidth [UIScreen mainScreen].bounds.size.width
10+
#define kHeight [UIScreen mainScreen].bounds.size.height
11+
#define kTopWindow [[UIApplication sharedApplication]keyWindow]
812

9-
static NSString *reuseIdentifier = @"clipBoardCell";
1013
static NSString *KBDockSettingsPlist = @"/var/mobile/Library/Preferences/com.nactro.kbdocksettings.plist";
1114
static NSString *bundleName = @"com.nactro.kbdock";
1215
static NSString *trialerLicensePath = @"/var/mobile/Library/nactro/trial/com.nactro.kbdock.dat";
@@ -121,12 +124,13 @@ static void verifySignature(){
121124
- (void)clipBoardBtnButtonClick:(id)sender{
122125
// UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
123126
// [[NSClassFromString(@"UIKeyboardImpl") activeInstance] insertText:pasteBoard.string];
124-
KBDockClipBoardViewController *vc = [[KBDockClipBoardViewController alloc]initWithViewFrame:CGRectMake(50, 50, 300, 300)];
127+
//KBDockClipBoardViewController *vc = [[KBDockClipBoardViewController alloc]initWithViewFrame:CGRectMake(0,kHeight - 375 ,kWidth, 375)];
128+
KBDockClipBoardViewController *vc = [[KBDockClipBoardViewController alloc]initWithViewFrame:CGRectMake(10,0,375 - 10 *2 ,400)];
125129
vc.view.alpha = 0.0;
126-
UIViewController *rootController = [UIApplication sharedApplication].keyWindow.rootViewController;
127-
[rootController addChildViewController:vc];
128-
[rootController.view addSubview:vc.view];
129-
vc.view.frame = rootController.view.bounds;
130+
UIViewController *inputVC = [self viewController];
131+
NSLog(@"dockView所在的控制器------>%@ ------>%f -------->%f",inputVC,inputVC.view.frame.size.height,inputVC.view.frame.size.width);
132+
[inputVC.view addSubview:vc.view];
133+
//vc.view.frame = [self viewController].view.bounds;
130134
[vc animateForPresentation];
131135
}
132136

@@ -158,9 +162,13 @@ static void verifySignature(){
158162
return %orig;
159163
}
160164
%end
161-
/* =========================== 重写「听写键」PopUpView ===================== */
162-
163-
165+
/* =========================== UIPasteboard ===================== */
166+
%hook UIPasteboard
167+
- (void)setString:(NSString *)arg1{
168+
[[NSNotificationCenter defaultCenter] postNotificationName:@"kbDidSetString" object:nil userInfo:@{@"string":arg1}];
169+
%orig;
170+
}
171+
%end
164172

165173
%ctor {
166174
//verifySignature();

KBDockClipBoardViewController.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "KBDockClipBoardViewController.h"
1010
#import "UIColor+Hex.h"
11+
#import "UIImpactFeedbackGenerator+Feedback.h"
1112

1213
static NSString *reuseIdentifier = @"kbdockClipBoard";
1314

@@ -51,6 +52,7 @@ - (void)viewDidLoad {
5152

5253
[self.view addSubview:self.backgroundView];
5354

55+
5456
self.darkeningView = [[UIView alloc] initWithFrame:CGRectZero];
5557
self.darkeningView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];
5658
self.darkeningView.userInteractionEnabled = NO;
@@ -83,6 +85,13 @@ - (void)_userDidTapCloseButton:(id)button {
8385
}];
8486
}
8587

88+
- (void)_userDidFinishPasting{
89+
[self animateForDismissalWithCompletion:^{
90+
[self removeFromParentViewController];
91+
[self.view removeFromSuperview];
92+
}];
93+
}
94+
8695
#pragma mark - Table view data source
8796

8897
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
@@ -104,7 +113,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
104113
}
105114

106115
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
116+
[UIImpactFeedbackGenerator generateFeedbackWithLightStyle];
107117
[tableView deselectRowAtIndexPath:indexPath animated:YES];
118+
[self _userDidFinishPasting];
108119
}
109120

110121
#pragma mark - 页面出现动画
@@ -152,7 +163,8 @@ - (NSMutableArray *)clipBoardArray{
152163
- (UITableView *)tableView{
153164
if (!_tableView) {
154165
_tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
155-
[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
166+
//[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
167+
_tableView.backgroundView.backgroundColor = [UIColor clearColor];
156168
[_tableView setTableHeaderView:[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0.01, 0.01)]];
157169
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIdentifier];
158170
}

UIView+Extend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#import <UIKit/UIKit.h>
2+
@interface UIView (Extend)
3+
- (UIViewController *)viewController;
4+
@end

UIView+Extend.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import "UIView+Extend.h"
2+
@implementation UIView (Extend)
3+
- (UIViewController *)viewController {
4+
for (UIView* next = [self superview]; next; next = next.superview) {
5+
UIResponder* nextResponder = [next nextResponder];
6+
if ([nextResponder isKindOfClass:[UIViewController class]]) {
7+
return (UIViewController*)nextResponder;
8+
}
9+
}
10+
return nil;
11+
}
12+
@end

0 commit comments

Comments
 (0)