更改UITextField的默认触摸事件 [英] Change default touch events for UITextField

查看:103
本文介绍了更改UITextField的默认触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以这就是我想要做的。我有一个UITextField。当我点击它时,我想调用我的一种方法。当我双击(用一根手指点击两次)时,我想编辑文本字段(好像我在普通的UITextField上点击它一样。)

Alright, so here is what I am trying to do. I have a UITextField. When I single tap it, I want to call one of my methods. When I double tap (tap it twice with 1 finger) it, I want to edit the text field (as though I had single tapped it on a normal UITextField.)

我不知道该怎么做。我正在考虑对UITextField进行子类化并尝试在发送时拦截触摸事件,但我无法确定要覆盖哪些方法来执行此操作。我应该覆盖哪些方法以及如何?

I am not sure how to go about this. I was thinking of sub-classing UITextField and trying to intercept the touch event as it is sent, but I can't figure out which methods to override to do this. Which methods should I override and how?

或者,如果有更好的方法,请告诉我们!我很满意,不知道如何继续。

Or, if there is a better way to do this, let me know! I'm all ears, and not sure how to proceed.

推荐答案

这将涉及几个步骤:

1。)添加一个NSBoolean属性,用于跟踪用户是否已经最近一次点击了该字段(您可以决定最近的含义)。

1.) Add a NSBoolean property that keeps track of whether the user has already tapped the field once recently (you get to decide what recently means here).

2。)实现分配给UITextField的委托的textFieldShouldBeginEditing:方法。如果用户快速连续点击两次(通过检查布尔属性是否为真可检测到),则返回YES。如果没有,请调用您的方法,然后返回NO。

2.) Implement the textFieldShouldBeginEditing: method of the delegate assigned to your UITextField. If the user has tapped twice in quick succession (detectable by checking whether or not the boolean property is true), then return YES. If not, call your method, and then return NO.

这篇关于更改UITextField的默认触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆