で非常に奇妙な動作が見られUITextField
ます。カスタムキーボードを実装しましたが、iOS 7 以降でうまく機能します。ただし、iOS 6 では、次の行が呼び出されると (「バックスペース」を実行した後)、テキスト フィールドのカーソルが消え、辞任して最初のレスポンダーに戻らない限り編集できず、プレースホルダーと実際のテキストが重なります。
私の「バックスペース」機能に関連するコードは次のとおりです。
//Get the position of the cursor
UITextPosition *selStartPos = self.textBeingEdited.selectedTextRange.start;
int start = (int)[self.textBeingEdited offsetFromPosition:self.textBeingEdited.beginningOfDocument toPosition:selStartPos];
//Make sure the cursor isn't at the front of the document
if (start > 0) {
//Remove the character before the cursor
self.textBeingEdited.text = [NSString stringWithFormat:@"%@%@", [self.textBeingEdited.text substringToIndex:start - 1], [self.textBeingEdited.text substringFromIndex:start]];
//Move the cursor back 1 (by default it'll go to the end of the string for some reason)
[self.textBeingEdited setSelectedTextRange:[self.textBeingEdited textRangeFromPosition:[self.textBeingEdited positionFromPosition:selStartPos offset:-1] toPosition:[self.textBeingEdited positionFromPosition:selStartPos offset:-1]]];
//^This line is causing the issue
}
そして、これが私がiOS 6で見ているものです:
誰でもこれについて何か洞察がありますか?ありがとう!
編集
これは、 として設定されているゼロ以外の値ごとに発生しているようoffset
です。