从UITapGestureRecognizer中删除目标

时间:2015-08-20 09:55:49

标签: ios xamarin xamarin.ios uigesturerecognizer target-action

我已将动作作为匿名方法添加到我的手势识别器

UITapGestureRecognizer tapGesture = new UITapGestureRecognizer ();
tapGesture.AddTarget (() => HandleTap (tapGesture));

如何删除目标? <{1}}是必需的。

1 个答案:

答案 0 :(得分:1)

RTFM在这里是正确的:

  

当您调用UIGestureRecognizer的UIGestureRecognizer.AddTarget方法时,将返回此类的实例。 AddTarget返回此标记,作为稍后使用UIGestureRecognizer.RemoveTarget方法从识别器取消订阅此特定操作的机制。

UIGestureRecognizer.Token token = tapGesture.AddTarget (() => HandleTap (tapGesture));

if (token != null) {
    tapGesture.RemoveTarget (token);
}