【问题标题】:Prevent default keyboard from showing when UITextField is pressed防止按下 UITextField 时显示默认键盘
【发布时间】:2010-07-04 19:03:39
【问题描述】:

有没有办法让自定义键盘在用户按下 UITextField 时弹出。我有一个带有自定义键盘的视图,我希望在用户按下 UITextField 而不是默认的苹果键盘时出现。

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitextfield


    【解决方案1】:

    从 iOS 3.2 开始,就有一个专门用于此的属性,称为 inputView。

    就像这样:[myTextField setInputView:myInputView] - myInputView 显然是您的自定义输入视图。然后系统会弹出你的视图而不是预定义的键盘。

    【讨论】:

    • 超级小费@Toastor。这在少数情况下非常方便,例如当您必须加载日期选择器以输入日期等时。谢谢!
    • 如果您希望键盘根本不显示,则将 inputView 设置为 nil 不起作用。您需要创建一个视图,即使它只有 1 px 正方形。
    【解决方案2】:

    您可以在 UITextField 中设置委托,并在 textFieldShouldBeginEditing 中返回 NO:。

    【讨论】:

      【解决方案3】:

      不确定我是否理解问题?键盘类型可以分配给 UITextField 所以如果你想要一个不同的然后在初始化对象时指定它

      UITextField * textFld = [[UITextField alloc] init];
      textFld.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
      

      http://developer.apple.com/iphone/library/documentation/uikit/reference/UITextInputTraits_Protocol/Reference/UITextInputTraits.html#//apple_ref/doc/c_ref/UIKeyboardType

      【讨论】:

      • 让我澄清一下。我有一个带有自定义键盘的视图,我希望在用户按下 UITextField 而不是默认的苹果键盘时出现。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      相关资源
      最近更新 更多