RemoveTarget from UITapGestureRecognizer

2019-07-11 14:21发布

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条回答
倾城 Initia
2楼-- · 2019-07-11 15:08

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);
}
查看更多
登录 后发表回答