-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKBDockClipBoardViewController.m
207 lines (165 loc) · 7.64 KB
/
KBDockClipBoardViewController.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
// KBDockClipBoardTableViewController.m
// kbdock
//
// Created by 开发者 on 2019/4/10.
// Copyright © 2019年 Nactro. All rights reserved.
//
#import "KBDockClipBoardViewController.h"
#import "UIColor+Hex.h"
#import "UIImpactFeedbackGenerator+Feedback.h"
#import "kbdocksettings/UIFont+Extension.h"
#define PREFERENCE_BUNDLE_PATH @"/Library/PreferenceBundles/retimesettings.bundle"
static NSString *reuseIdentifier = @"kbdockClipBoard";
@interface KBDockClipBoardViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)NSMutableArray *clipBoardArray;
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong) UIVisualEffectView *backgroundView;
@property (nonatomic, strong) UIView *darkeningView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UITapGestureRecognizer *closeGestureRecogniser;
@end
@implementation KBDockClipBoardViewController
#pragma mark - overide init method
- (instancetype)initWithViewFrame:(CGRect)frame{
self = [super init];
if (self) {
self.contentView = [[UIView alloc]initWithFrame:frame];
//self.contentView.clipsToBounds = YES;
//self.contentView.layer.cornerRadius = 12.5;
// [self.contentView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
// [self.contentView.layer setBorderWidth:0.8f];
self.contentView.backgroundColor = [UIColor clearColor];
self.contentView.userInteractionEnabled = YES;
[self.view addSubview:self.contentView];
}
return self;
}
#pragma mark - Class methods
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.backgroundView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.backgroundView.contentView.userInteractionEnabled = YES;
[self.view addSubview:self.backgroundView];
self.darkeningView = [[UIView alloc] initWithFrame:CGRectZero];
self.darkeningView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];
self.darkeningView.userInteractionEnabled = NO;
[self.backgroundView.contentView addSubview:self.darkeningView];
self.tableView.frame = self.contentView.bounds;
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.contentView addSubview:self.tableView];
self.backgroundView.frame = self.view.bounds;
self.darkeningView.frame = self.backgroundView.bounds;
self.closeGestureRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_userDidTapCloseButton:)];
[self.backgroundView.contentView addGestureRecognizer:self.closeGestureRecogniser];
[self initData];
}
- (void)initData{
// handle data
}
// - (CGFloat)getWholeCellHeight{
// return 5 * 60;
// }
- (void)_userDidTapCloseButton:(id)button {
// animate out, and hide.
[self animateForDismissalWithCompletion:^{
[self removeFromParentViewController];
[self.view removeFromSuperview];
}];
}
- (void)_userDidFinishPasting{
[self animateForDismissalWithCompletion:^{
[self removeFromParentViewController];
[self.view removeFromSuperview];
}];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
cell.textLabel.font = [UIFont PingFangLightForSize:18];
cell.backgroundColor = [UIColor whiteColor];
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor = [UIColor colorWithHexString:@"#006fff"];
cell.textLabel.highlightedTextColor = [UIColor whiteColor];
//cell.detailTextLabel.highlightedTextColor = [UIColor whiteColor];
cell.textLabel.text = @"I don't give a shit about society!";
//cell.detailTextLabel.text = @"nonononono";
//cell.detailTextLabel.textColor = [UIColor blackColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.imageView.image = [UIImage imageWithContentsOfFile:[PREFERENCE_BUNDLE_PATH stringByAppendingPathComponent:@"placeholder.png"]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[UIImpactFeedbackGenerator generateFeedbackWithLightStyle];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self _userDidFinishPasting];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
[cell setSeparatorInset:UIEdgeInsetsMake(0, 5, 0, 5)];
//[cell setSeparatorInset:UIEdgeInsetsZero];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60;
}
#pragma mark - 页面出现动画
- (void)animateForPresentation {
self.contentView.frame = CGRectMake(self.contentView.frame.origin.x, self.view.frame.size.height, self.contentView.frame.size.width, self.contentView.frame.size.height);
self.view.alpha = 0.0;
[UIView animateWithDuration:0.3
delay:0.0
usingSpringWithDamping:0.765
initialSpringVelocity:0.15
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.view.alpha = 1.0;
self.contentView.frame = CGRectMake(self.contentView.frame.origin.x, self.view.frame.size.height/2 - self.contentView.frame.size.height/2, self.contentView.frame.size.width, self.contentView.frame.size.height);
} completion:^(BOOL finished) {
}];
}
#pragma mark - 页面消失动画
- (void)animateForDismissalWithCompletion:(void (^)(void))completionHandler {
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.view.alpha = 0.0;
self.contentView.frame = CGRectMake(self.contentView.frame.origin.x, self.view.frame.size.height, self.contentView.frame.size.width, self.contentView.frame.size.height);
} completion:^(BOOL finished) {
if (finished) {
self.contentView.transform = CGAffineTransformMakeScale(1.0, 1.0);
completionHandler();
}
}];
}
#pragma mark - lazyload
- (NSMutableArray *)clipBoardArray{
if (!_clipBoardArray) {
_clipBoardArray = [NSMutableArray array];
}
return _clipBoardArray;
}
- (UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
//[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
//_tableView.separatorColor = [UIColor whiteColor];
_tableView.backgroundColor = [UIColor colorWithHexString:@"#f0f0f0"];
_tableView.showsVerticalScrollIndicator = NO;
[_tableView setTableHeaderView:[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0.01, 0.01)]];
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIdentifier];
}
return _tableView;
}
@end