简体   繁体   中英

Prediction view is under keyboard keys

I have an UILabel subclass, conforming UIKeyInputs protocol. But when the keyboard is shown, prediction view is under keyboard keys: Here is the screenshot:

镜头

And here is the implementation:

class CustomLabel: UILabel {
    // some implementation, nothing important to effect keyboard.
}

extension CustomLabel: UIKeyInput {

  var hasText: Bool {
    if let text = self.text {
      return text.isEmpty
    }
    return false
  }

  func insertText(_ text: String) {
    self.text?.append(text)
  }

  func deleteBackward() {
    guard let text = self.text else { return }
    self.text = String(text.dropLast())
  }

  override var canBecomeFirstResponder: Bool {
    return true
  }

  private var autocapitalizationType: UITextAutocapitalizationType {
    return .none
  }

  private var autocorrectionType: UITextAutocorrectionType {
    return .no
  }

  private var spellCheckingType: UITextSpellCheckingType {
    return .no
  }

  private var keyboardType: UIKeyboardType {
    return .twitter
  }

  private var returnKeyType: UIReturnKeyType {
    return .done
  }

  private var keyboardAppearance: UIKeyboardAppearance {
    return .default
  }

}

One thing that I did not understand is autocapitalizationType, autocorrectionType and other protocol methods for keyboard appearance are not called.

I hope someone can help. Thank you.

for Swift4 you must use UITextInputTraits as

@objc var keyboardType: UIKeyboardType = .default
@objc var autocorrectionType: UITextAutocorrectionType = .no

or

@objc  var keyboardAppearance: UIKeyboardAppearance {
    get { return .dark }
    set(value) {}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM