ibireme / YYText

Powerful text framework for iOS to display and edit rich text.
MIT License
8.84k stars 1.67k forks source link

_YYTextKeyboardViewFrameObserver崩溃 #978

Open zhazhaYang opened 1 year ago

zhazhaYang commented 1 year ago
__unsafe_unretained UIView *_keyboardView;

推测:_keyboardView在_YYTextKeyboardViewFrameObserver对象dealloc前被释放掉了,导致访问了野指针。很可能两者的关联处理有关系。 场景:并未使用YY相关组件,而是使用了UITextField,调起了键盘。YYTextKeyboardManager单例收到了UIKeyboardDidChangeFrameNotification通知,最后导致的崩溃。

zhazhaYang commented 1 year ago

查了issues似乎有两个相关问题,麻烦看看呢。 https://github.com/ibireme/YYText/issues/842 https://github.com/ibireme/YYText/issues/924

yasinn commented 1 year ago

查了issues似乎有两个相关问题,麻烦看看呢。 #842 #924

这个有解决方法吗?

zhazhaYang commented 1 year ago

查了issues似乎有两个相关问题,麻烦看看呢。 #842 #924

这个有解决方法吗?

我用分类覆盖了他有问题的地方

duoshankui commented 1 year ago

哈喽,能分享一下你的处理方案吗,我也遇到这个问题了

zhazhaYang commented 1 year ago

哈喽,能分享一下你的处理方案吗,我也遇到这个问题了

@implementation YYTextKeyboardManager (Helper)

duoshankui commented 1 year ago

哈喽,能分享一下你的处理方案吗,我也遇到这个问题了

@implementation YYTextKeyboardManager (Helper)

  • (void)_initFrameObserver { UIView keyboardView = self.keyboardView; if (!keyboardView) { return; } UIView lastKeyboard = [[self weakPropertyMap] objectForKey:@"keyboardView"]; if(lastKeyboard == keyboardView) { return; } [[self weakPropertyMap] setObject:keyboardView forKey:@"keyboardView"]; weak typeof(self) weakSelf = self; weak UIView *weakKeyboardView = keyboardView; SEL sel = NSSelectorFromString(@"_keyboardFrameChanged:"); void(^block)(id x) = ^(id x) { if(weakKeyboardView && [weakSelf respondsToSelector:sel]) {

    pragma clang diagnostic push

    pragma clang diagnostic ignored "-Warc-performSelector-leaks"

    [weakSelf performSelector:sel withObject:weakKeyboardView];

    pragma clang diagnostic pop

    } }; [RACObserve(keyboardView, frame) subscribeNext:block]; [RACObserve(keyboardView, center) subscribeNext:block]; [RACObserve(keyboardView, bounds) subscribeNext:block]; [RACObserve(keyboardView, transform) subscribeNext:block]; }

哈哈,好惭愧,我是这么解决的, @implementation YYTextKeyboardManager (FixCrash)

pragma clang diagnostic push

pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

@end

460467069 commented 7 months ago

哈喽,能分享一下你的处理方案吗,我也遇到这个问题了

@implementation YYTextKeyboardManager (Helper)

  • (void)_initFrameObserver { UIView keyboardView = self.keyboardView; if (!keyboardView) { return; } UIView lastKeyboard = [[self weakPropertyMap] objectForKey:@"keyboardView"]; if(lastKeyboard == keyboardView) { return; } [[self weakPropertyMap] setObject:keyboardView forKey:@"keyboardView"]; weak typeof(self) weakSelf = self; weak UIView *weakKeyboardView = keyboardView; SEL sel = NSSelectorFromString(@"_keyboardFrameChanged:"); void(^block)(id x) = ^(id x) { if(weakKeyboardView && [weakSelf respondsToSelector:sel]) {

    pragma clang diagnostic push

    pragma clang diagnostic ignored "-Warc-performSelector-leaks"

    [weakSelf performSelector:sel withObject:weakKeyboardView];

    pragma clang diagnostic pop

    } }; [RACObserve(keyboardView, frame) subscribeNext:block]; [RACObserve(keyboardView, center) subscribeNext:block]; [RACObserve(keyboardView, bounds) subscribeNext:block]; [RACObserve(keyboardView, transform) subscribeNext:block]; }

weakPropertyMap 这个实现方法是啥呀?