【问题标题】:How do you disable the double tap keyboard popup in a UITextField?如何禁用 UITextField 中的双击键盘弹出窗口?
【发布时间】:2011-08-10 16:30:06
【问题描述】:

我有几个 UITextFields。我想禁用带来自动更正/键盘的“双击”。我正在使用点击功能来选择要激活的 UITextField。

【问题讨论】:

  • 单击即可调出键盘 -- 双击有什么用?
  • 单击选择 UITextField。当我双击它时,它会调出键盘。我不会禁用双击键盘。
  • 您必须创建双击手势,因为默认行为是在您第一次点击文本字段时调出键盘。它不会在单击时“选择”它。
  • 代码示例:tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecieved:)]; tex2.userInteractionEnabled = YES; [tex2 addGestureRecognizer:tap]; [点击释放];点击=无;

标签: iphone ios4 iphone-sdk-3.0


【解决方案1】:

您可以使用 UITextView 的 textFieldShouldBeginEditing Delegate 方法告诉 UITextField 不要开始编辑过程:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  if (some conditon) {
    return NO;
  } else {
    return YES;
  }
}

有关方法的 Apple 文档参考: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html

some condition 可能会检查用户是否选择了 UITextField 来激活它,或者它是否已经处于活动状态并且应该打开键盘。

您可以将 UITextView 子类化以赋予它“选定”属性,并使其成为 UITextViewDelegate。如果 "selected" 为 false,则在 textFieldShouldBeginEditing: 中将其设置为 true 并返回 NO;否则,返回 YES。这只是我脑海中的一个随机想法。

【讨论】:

  • 这是我用来激活 UITextfield 的。我只想禁用编辑键盘(双击)。代码示例:tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecieved:)]; tex2.userInteractionEnabled = YES; [tex2 addGestureRecognizer:tap]; [点击释放];点击=无;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多