问题
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