我需要在文本视图中使用两种不同的字体,因此我在textViewDidChange中设置了attributedText。但是对于日语键盘,输入字符会重复输入。
对于英语键盘,它可以正常工作。当您使用普通文本而不是attributedText时,对于日语键盘也有效。
我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] initWithFrame:self.view.frame];
textView.delegate = self;
[self.view addSubview:textView];
}
- (void)textViewDidChange:(UITextView *)textView
{
NSLog(@"TOTAL: %@", textView.text);
textView.attributedText = [[NSMutableAttributedString alloc] initWithString: textView.text];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"ADDED: %@", text);
return YES;
}
输出:
2015-07-15 13:51:10.156 japKeyTest[32163:5765000] ADDED: a
2015-07-15 13:51:10.167 japKeyTest[32163:5765000] TOTAL: あ
2015-07-15 13:51:11.376 japKeyTest[32163:5765000] ADDED: a
2015-07-15 13:51:11.378 japKeyTest[32163:5765000] TOTAL: あああ
2015-07-15 13:51:12.054 japKeyTest[32163:5765000] ADDED: a
2015-07-15 13:51:12.055 japKeyTest[32163:5765000] TOTAL: ああああああ
期望结果:
2015-07-15 13:51:10.156 japKeyTest[32163:5765000] ADDED: a
2015-07-15 13:51:10.167 japKeyTest[32163:5765000] TOTAL: あ
2015-07-15 13:51:11.376 japKeyTest[32163:5765000] ADDED: a
2015-07-15 13:51:11.378 japKeyTest[32163:5765000] TOTAL: ああ
2015-07-15 13:51:12.054 japKeyTest[32163:5765000] ADDED: a
2015-07-15 13:51:12.055 japKeyTest[32163:5765000] TOTAL: あああ
有没有办法使用日语键盘输入带有属性的文本并获得正常结果?(不带额外字符)