繁体   English   中英

预测视图在键盘按键下

[英]Prediction view is under keyboard keys

我有一个UILabel子类,符合UIKeyInputs协议。 但是当显示键盘时,预测视图位于键盘键下:这是屏幕截图:

镜头

这是实现:

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
  }

}

我不了解的一件事是没有调用autocapitalizationType,autocorrectionType和其他用于键盘外观的协议方法。

我希望有人能帮帮忙。 谢谢。

对于Swift4您必须使用UITextInputTraits作为

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

要么

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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