Jak*_*dak 7 keyboard objective-c uitextview ios
我需要在文本视图中使用两种不同的字体,因此我在textViewDidChange中设置了属性Text.但是对于日语键盘,输入字符会重复输入.
它适用于英文键盘.当您使用普通文本而不是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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
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: ??????
Run Code Online (Sandbox Code Playgroud)
预期:
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: ???
Run Code Online (Sandbox Code Playgroud)
知道如何用日语键盘输入属性文本并获得正常结果吗?(没有额外的字符)
我的经验告诉我,UIKit只要-attributedTextaUITextField或 的属性UITextView在 - 期间被修改textView(Field)DidChange time(就像在您的示例中一样),该错误(我相信这是一个错误)就会显现出来。
就我而言,我能够更改代码,以便在那段时间不会发生更新(在我的情况下根本不需要更新,所以这很容易)。
如果您当时需要更新属性文本,我所能建议的就是向 Apple 提交错误并等待(永远或更长时间)。
请注意,即使您只更新这些对象的 -text 属性,您也可能会看到此错误 - 因为UIKit有时(总是?)会-attributedText在您更新-text. (您可以通过对这些对象进行子类化并覆盖-setAttributedText:并设置断点来看到这一点。
祝你好运
编辑:到目前为止,我只在日语键盘上看到过这个错误,但随着我在应用程序使用其他语言方面获得更多经验,看到更多问题我不会感到惊讶。
| 归档时间: |
|
| 查看次数: |
1091 次 |
| 最近记录: |