处理键盘崩溃
This commit is contained in:
@@ -49,7 +49,6 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5;
|
||||
self.layoutConfig = [KBKeyboardLayoutConfig sharedConfig];
|
||||
self.backspaceHandler = [[KBBackspaceLongPressHandler alloc] initWithContainerView:self];
|
||||
[self buildBase];
|
||||
[self reloadKeys];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user