iOS 输入中文自动补英文bug
** Bug 原因:**
UITextField、UITextView 使用了 ReactiveObjC
、ReactiveCocoa
的 rac_textSignal
方法导致
** 解决办法: **
给UITextField、UITextView 添加分类代替 ReactiveObjC
、ReactiveCocoa
的 rac_textSignal
方法:
** UITextField 分类:**
#import "UITextField+Add.h"
#import "NSObject+RACDescription.h"
- (RACSignal *)rac_inputTextSignal {
@weakify(self);
return [[[[[[RACSignal
defer:^{
@strongify(self);
return [RACSignal return:self];
}]
concat:[self rac_signalForControlEvents:UIControlEventAllEditingEvents]]
filter:^BOOL(UITextField *x) {
if (!x.markedTextRange) {
return YES;
} else {
return NO;
}
}]
map:^(UITextField *x) {
return x.text;
}]
takeUntil:self.rac_willDeallocSignal]
setNameWithFormat:@"%@ -rac_inputTextSignal", RACDescription(self)];
}
@end
** UITextView 分类:**
#import "UITextView+Add.h"
#import "NSObject+RACDescription.h"
@implementation UITextView (Add)
static void RACUseDelegateProxy_(UITextView *self) {
if (self.delegate == (id)self.rac_delegateProxy) return;
self.rac_delegateProxy.rac_proxiedDelegate = self.delegate;
self.delegate = (id)self.rac_delegateProxy;
}
- (RACSignal *)rac_inputTextSignal {
@weakify(self);
RACSignal *signal = [[[[[[[RACSignal
defer:^{
@strongify(self);
return [RACSignal return:RACTuplePack(self)];
}]
concat:[self.rac_delegateProxy signalForSelector:@selector(textViewDidChange:)]]
reduceEach:^(UITextView *x) {
return x;
}]
filter:^BOOL(UITextView *x) {
if (!x.markedTextRange) {
return YES;
} else {
return NO;
}
}]
map:^(UITextView *x) {
return x.text;
}]
takeUntil:self.rac_willDeallocSignal]
setNameWithFormat:@"%@ -rac_inputTextSignal", RACDescription(self)];
RACUseDelegateProxy_(self);
return signal;
}
@end
希望对您有帮助!
如有帮助,劳烦您随手一赞,谢谢!
网友评论