RemoveTarget from UITapGestureRecognizer

扶醉桌前 提交于 2019-12-13 14:04:14

问题


I've added an action as anonymous method to my gesture recognizer

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

How can I remove the target? UIGestureRecognizer.Token is needed.


回答1:


RTFM is true here:

An instance of this class is returned when you invoke the UIGestureRecognizer's UIGestureRecognizer.AddTarget method. The AddTarget returns this token as a mechanism for later unsubscribing this particular action from the recognizer using the UIGestureRecognizer.RemoveTarget method.

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

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


来源:https://stackoverflow.com/questions/32115108/removetarget-from-uitapgesturerecognizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!