带有点击事件的 UITapGestureRecognizer
UITapGestureRecognizer with tap event
我正在尝试在不同的 uiview 上使用 UITapGestureRecognizer 触发事件,但它不起作用。
var tap = UITapGestureRecognizer(target: self, action: Selector("tappedMe"))
AUIView.addGestureRecognizer(tap)
AUIView.tag = 1
BUIView.addGestureRecognizer(tap)
BUIView.tag = 2
func tappedMe()
{
if AUIView.tag == 1
{
println("1")
}
else if BUIView.tag == 2
{
println("2")
}
}
您不能将相同的手势识别器添加到多个视图。这 answer 解释了原因。
要么声明一个新的手势识别器,要么创建现有手势识别器的副本,然后再将其添加到另一个视图。
BUIView.addGestureRecognizer(tap.copy())
我正在尝试在不同的 uiview 上使用 UITapGestureRecognizer 触发事件,但它不起作用。
var tap = UITapGestureRecognizer(target: self, action: Selector("tappedMe"))
AUIView.addGestureRecognizer(tap)
AUIView.tag = 1
BUIView.addGestureRecognizer(tap)
BUIView.tag = 2
func tappedMe()
{
if AUIView.tag == 1
{
println("1")
}
else if BUIView.tag == 2
{
println("2")
}
}
您不能将相同的手势识别器添加到多个视图。这 answer 解释了原因。
要么声明一个新的手势识别器,要么创建现有手势识别器的副本,然后再将其添加到另一个视图。
BUIView.addGestureRecognizer(tap.copy())