【发布时间】:2023-03-17 03:43:02
【问题描述】:
我需要在文本视图中使用两种不同的字体,所以我在 textViewDidChange 中设置了属性文本。但是对于日文键盘,输入字符是重复输入的。
它适用于英文键盘。 当您使用普通文本而不是属性文本时,它也适用于日文键盘。
我的代码:
- (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: あああ
知道如何使用日文键盘输入属性文本并获得正常结果吗? (没有多余的字符)
【问题讨论】:
-
这个巧合真是太棒了:我刚开始一份新工作,这是我尝试修复的第一个错误。我不敢相信这不会影响成千上万支持日语的应用程序!
-
另外:尝试使用罗马字输入“mika”,看看是否在多余字符中间出现“k”!我确定这是同一个错误。
-
使用普通英文键盘的我也会发生这种情况。
标签: ios objective-c keyboard uitextview