iOS - 向UITextField添加Tap Gesture [英] iOS - Add Tap Gesture to UITextField

查看:656
本文介绍了iOS - 向UITextField添加Tap Gesture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在向UITextField添加Tap Gesture时遇到问题。代码如下:

I have problem with add a Tap Gesture to my UITextField. Below code:

@IBAction func hanldeTap(recognizer: UITapGestureRecognizer) {
    println("works")
}

此操作与Tap Gesture Recognizer相关联。在我的TextField中,我在 OutletCollections 中定义了 gestureRecognizer 。在我的猜测它应该工作。在所描述的配置中,手势工作e.x.用于按钮或自定义视图。

This action is associated with Tap Gesture Recognizer. In my TextField I have defined gestureRecognizer in OutletCollections. In my guess it should works. In described configuration gesture works e.x. for button or custom view.

你能告诉我可能出现的问题以及如何解决这个问题?

Can you tell my what could go wrong and how can I fix this?

推荐答案

UITextField有委托方法,您可能需要考虑实施这些方法。或者只是将动作事件添加到您的文本字段。

UITextField has delegate methods, you might want to consider implementing those. Or just add action event to your textfield.

例如在 viewDidLoad

textField.addTarget(self, action:Selector("textDidBeginEditing"), forControlEvents: UIControlEvents.EditingDidBegin)

然后实现:

func textDidBeginEditing(sender:UITextField) -> Void
{
   // handle begin editing event
} 

这篇关于iOS - 向UITextField添加Tap Gesture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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