开发者

Change default touch events for 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.)

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.


This would involve several steps:

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.) 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜