1
This commit is contained in:
@@ -480,10 +480,10 @@ static NSString * const KBAISelectedPersonaIdKey = @"KBAISelectedPersonaId";
|
||||
[ud setObject:personaDict forKey:@"AppGroup_SelectedPersona"];
|
||||
[ud synchronize];
|
||||
|
||||
NSLog(@"[KBAIHomeVC] 已保存选中的 persona 到 AppGroup: %@, coverImageUrl: %@", persona.name, persona.coverImageUrl);
|
||||
|
||||
NSLog(@"[KBAIHomeVC] 已保存选中的 persona 到 AppGroup: %@, avatarUrl: %@", persona.name, persona.avatarUrl);
|
||||
|
||||
// 异步下载并缩小图片,保存到 AppGroup 共享目录
|
||||
[self downloadAndSavePersonaCoverImage:persona.coverImageUrl];
|
||||
[self downloadAndSavePersonaCoverImage:persona.avatarUrl];
|
||||
}
|
||||
|
||||
/// 下载并缩小 persona 封面图,保存到 AppGroup 共享目录
|
||||
@@ -511,18 +511,17 @@ static NSString * const KBAISelectedPersonaIdKey = @"KBAISelectedPersonaId";
|
||||
return;
|
||||
}
|
||||
|
||||
// 缩小图片到适合键盘扩展的尺寸(宽度 390,高度按比例)
|
||||
CGFloat targetWidth = 390.0;
|
||||
CGFloat scale = targetWidth / image.size.width;
|
||||
CGSize targetSize = CGSizeMake(targetWidth, image.size.height * scale);
|
||||
|
||||
UIGraphicsBeginImageContextWithOptions(targetSize, YES, 1.0);
|
||||
// 缩小图片到 40x40(仅用于工具栏头像显示)
|
||||
CGFloat targetSide = 40.0;
|
||||
CGSize targetSize = CGSizeMake(targetSide, targetSide);
|
||||
|
||||
UIGraphicsBeginImageContextWithOptions(targetSize, NO, 1.0);
|
||||
[image drawInRect:CGRectMake(0, 0, targetSize.width, targetSize.height)];
|
||||
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
// 压缩为 JPEG,质量 0.6
|
||||
NSData *jpegData = UIImageJPEGRepresentation(scaledImage, 0.6);
|
||||
|
||||
// 压缩为 JPEG,质量 0.8
|
||||
NSData *jpegData = UIImageJPEGRepresentation(scaledImage, 0.8);
|
||||
if (!jpegData) {
|
||||
NSLog(@"[KBAIHomeVC] 压缩图片失败");
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBKeyboardStressTestVC : BaseViewController
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
142
keyBoard/Class/Home/VC/FunctionTest/KBKeyboardStressTestVC.m
Normal file
142
keyBoard/Class/Home/VC/FunctionTest/KBKeyboardStressTestVC.m
Normal file
@@ -0,0 +1,142 @@
|
||||
#import "KBKeyboardStressTestVC.h"
|
||||
|
||||
@interface KBKeyboardStressTestVC ()
|
||||
@property(nonatomic, strong) UITextView *textView;
|
||||
@property(nonatomic, strong) UIButton *startButton;
|
||||
@property(nonatomic, strong) UIButton *stopButton;
|
||||
@property(nonatomic, strong) UILabel *statusLabel;
|
||||
@property(nonatomic, assign) NSInteger currentCycle;
|
||||
@property(nonatomic, assign) NSInteger totalCycles;
|
||||
@property(nonatomic, assign) BOOL running;
|
||||
@end
|
||||
|
||||
@implementation KBKeyboardStressTestVC
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = UIColor.whiteColor;
|
||||
self.title = @"键盘压力测试";
|
||||
self.totalCycles = 200;
|
||||
[self buildUI];
|
||||
[self updateStatus];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
[self stop];
|
||||
}
|
||||
|
||||
- (void)buildUI {
|
||||
CGFloat w = UIScreen.mainScreen.bounds.size.width;
|
||||
|
||||
self.statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, KB_NAV_TOTAL_HEIGHT + 16, w - 32, 22)];
|
||||
self.statusLabel.font = [UIFont systemFontOfSize:13];
|
||||
self.statusLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1];
|
||||
[self.view addSubview:self.statusLabel];
|
||||
|
||||
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(16, CGRectGetMaxY(self.statusLabel.frame) + 12, w - 32, 160)];
|
||||
self.textView.text = @"把系统输入法切到自定义键盘后,点击开始,会反复显示/隐藏键盘。";
|
||||
self.textView.layer.borderColor = [UIColor colorWithWhite:0 alpha:0.15].CGColor;
|
||||
self.textView.layer.borderWidth = 0.5;
|
||||
self.textView.layer.cornerRadius = 8;
|
||||
[self.view addSubview:self.textView];
|
||||
|
||||
CGFloat btnW = (w - 16 * 2 - 12) / 2.0;
|
||||
self.startButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
self.startButton.frame = CGRectMake(16, CGRectGetMaxY(self.textView.frame) + 16, btnW, 44);
|
||||
self.startButton.layer.cornerRadius = 10;
|
||||
self.startButton.backgroundColor = [UIColor colorWithRed:0.22 green:0.49 blue:0.96 alpha:1];
|
||||
[self.startButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
||||
[self.startButton setTitle:@"开始" forState:UIControlStateNormal];
|
||||
[self.startButton addTarget:self action:@selector(onStart) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:self.startButton];
|
||||
|
||||
self.stopButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
self.stopButton.frame = CGRectMake(CGRectGetMaxX(self.startButton.frame) + 12, CGRectGetMinY(self.startButton.frame), btnW, 44);
|
||||
self.stopButton.layer.cornerRadius = 10;
|
||||
self.stopButton.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.08];
|
||||
[self.stopButton setTitleColor:[UIColor colorWithWhite:0.15 alpha:1] forState:UIControlStateNormal];
|
||||
[self.stopButton setTitle:@"停止" forState:UIControlStateNormal];
|
||||
[self.stopButton addTarget:self action:@selector(onStop) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:self.stopButton];
|
||||
|
||||
UIButton *oneCycleBtn = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
oneCycleBtn.frame = CGRectMake(16, CGRectGetMaxY(self.startButton.frame) + 12, w - 32, 44);
|
||||
oneCycleBtn.layer.cornerRadius = 10;
|
||||
oneCycleBtn.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.08];
|
||||
[oneCycleBtn setTitleColor:[UIColor colorWithWhite:0.15 alpha:1] forState:UIControlStateNormal];
|
||||
[oneCycleBtn setTitle:@"执行 10 次" forState:UIControlStateNormal];
|
||||
[oneCycleBtn addTarget:self action:@selector(onRunTen) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:oneCycleBtn];
|
||||
}
|
||||
|
||||
- (void)onStart {
|
||||
self.totalCycles = 200;
|
||||
[self start];
|
||||
}
|
||||
|
||||
- (void)onRunTen {
|
||||
self.totalCycles = 10;
|
||||
[self start];
|
||||
}
|
||||
|
||||
- (void)onStop {
|
||||
[self stop];
|
||||
}
|
||||
|
||||
- (void)start {
|
||||
if (self.running) {
|
||||
return;
|
||||
}
|
||||
self.running = YES;
|
||||
self.currentCycle = 0;
|
||||
[self updateStatus];
|
||||
[self runNextCycle];
|
||||
}
|
||||
|
||||
- (void)stop {
|
||||
self.running = NO;
|
||||
[self.textView resignFirstResponder];
|
||||
[self updateStatus];
|
||||
}
|
||||
|
||||
- (void)runNextCycle {
|
||||
if (!self.running) {
|
||||
return;
|
||||
}
|
||||
if (self.currentCycle >= self.totalCycles) {
|
||||
[self stop];
|
||||
return;
|
||||
}
|
||||
|
||||
self.currentCycle += 1;
|
||||
[self updateStatus];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.textView becomeFirstResponder];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.18 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
if (!self || !self.running) {
|
||||
return;
|
||||
}
|
||||
[self.textView resignFirstResponder];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.12 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
[self runNextCycle];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
- (void)updateStatus {
|
||||
NSString *run = self.running ? @"运行中" : @"未运行";
|
||||
self.statusLabel.text = [NSString stringWithFormat:@"状态:%@ | 进度:%ld/%ld", run, (long)self.currentCycle, (long)self.totalCycles];
|
||||
self.startButton.enabled = !self.running;
|
||||
self.startButton.alpha = self.running ? 0.5 : 1.0;
|
||||
self.stopButton.enabled = self.running;
|
||||
self.stopButton.alpha = self.running ? 1.0 : 0.5;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user