处理键盘崩溃

This commit is contained in:
2026-02-10 13:22:19 +08:00
parent 4c57f16058
commit 3c71797b7b
5 changed files with 459 additions and 99 deletions

View File

@@ -9,6 +9,7 @@
#import "KBResponderUtils.h" // UIInputViewController
#import "KBBackspaceUndoManager.h"
#import "KBSkinManager.h"
#import <ImageIO/ImageIO.h>
@interface KBToolBar ()
@property (nonatomic, strong) UIView *leftContainer;
@@ -20,6 +21,8 @@
@property (nonatomic, assign) BOOL kbNeedsInputModeSwitchKey;
@property (nonatomic, assign) BOOL kbUndoVisible;
@property (nonatomic, assign) BOOL kbAvatarVisible;
@property (nonatomic, copy, nullable) NSString *kb_cachedPersonaCoverPath;
@property (nonatomic, strong, nullable) UIImage *kb_cachedPersonaCoverImage;
@end
@implementation KBToolBar
@@ -256,10 +259,41 @@
[[containerURL path] stringByAppendingPathComponent:@"persona_cover.jpg"];
if (imagePath.length == 0 ||
![[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
self.kb_cachedPersonaCoverPath = nil;
self.kb_cachedPersonaCoverImage = nil;
return nil;
}
return [UIImage imageWithContentsOfFile:imagePath];
if (self.kb_cachedPersonaCoverImage &&
[self.kb_cachedPersonaCoverPath isEqualToString:imagePath]) {
return self.kb_cachedPersonaCoverImage;
}
// 40pt full decode JPG
NSUInteger maxPixel = 256;
NSURL *url = [NSURL fileURLWithPath:imagePath];
CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL);
if (!source) {
return nil;
}
NSDictionary *opts = @{
(__bridge id)kCGImageSourceCreateThumbnailFromImageAlways : @YES,
(__bridge id)kCGImageSourceCreateThumbnailWithTransform : @YES,
(__bridge id)kCGImageSourceThumbnailMaxPixelSize : @(maxPixel),
};
CGImageRef cg = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef)opts);
CFRelease(source);
if (!cg) {
return nil;
}
UIImage *img = [UIImage imageWithCGImage:cg
scale:[UIScreen mainScreen].scale
orientation:UIImageOrientationUp];
CGImageRelease(cg);
self.kb_cachedPersonaCoverPath = imagePath;
self.kb_cachedPersonaCoverImage = img;
return img;
}
#pragma mark - Actions