선행 공백을 허용하지 않으려는 textField가 있습니다. 그래서 textField(textField:shouldChangeCharactersInRange:replacementString:)
을 구현하고 텍스트를 공백으로 시작하는 것으로 변경하려는 시도를 차단합니다. 이것은 예상대로 작동합니다.QuickType 예측에서 UITextFieldDelegate에 의해 차단되어야하는 키 스트로크를받습니다.
불행히도 이것은 퀵타임을 엉망으로 만듭니다. 빈 필드에서 공백을 누를 때마다 내 textField에서 무시할 때마다 Quicktype 텍스트 앞에이 공백이옵니다. 더 명확하게 말하면, QuickType이 삽입 할 텍스트 앞에 접두사가 붙습니다. 추가 공백은 QuickType 막대의 UI에 표시되지 않습니다. 여기
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let currentText = textField.text as NSString
let proposedText = currentText.stringByReplacingCharactersInRange(range, withString: string)
if !proposedText.isEmpty {
let firstCharacterString = String(proposedText[proposedText.startIndex]) as NSString
if firstCharacterString.rangeOfCharacterFromSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).location == 0 {
println("starts with whitespace \"\(proposedText)\"")
return false
}
}
return true
}
는 I 공간 께
I'm
QuickType 제안 눌러 다음 5 번 누르면, 일부 기록이 일어나고 있는지 확인할 수있다 :
starts with whitespace " " // pressing space key
starts with whitespace " "
starts with whitespace " "
starts with whitespace " "
starts with whitespace " "
starts with whitespace " I'm" // Inserted by QuickType after pressing the "I'm" suggestion
starts with whitespace " " // Inserted by QuickType as well
를 I는 것을 확인할 수 위임 방법의 변수를 검사함으로써 문제는 실제로 UITextField에서 가져 오는 대체 문자열입니다. 그것은 공백으로 시작되는 제안을 이미 포함하고 있습니다.
누구나 내가 그것을 막을 수 있는지 또는 어떻게 QuickType 제안을 "재설정"할 수 있는지 알고 있습니까?
해결 방법은 여러 문자 삽입에서 공백을 제거하는 것이지만 처음에는 문제를 깨끗하게 처리 할 방법이 없는지 확인하고 싶습니다.