facebookarchive / AsyncDisplayKit

Smooth asynchronous user interfaces for iOS apps.

Home Page:http://asyncdisplaykit.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I catch a click on a ASDisplayNode?

giangpham96 opened this issue · comments

I have a class that extends ASDisplayNode, let call it GNode. GNode contains some other sub-nodes.
The problem is now I want to detect when a user clicks on that GNode. I have read some of your answers to other issues and known that the addTarget method is only available to control nodes.
So how can I achieve this?

I'm new to Texture as well as iOS Development. Please help me 🤔 I'm very appreciate

@giangpham96 Please move this over to the Texture project (texturegroup.org), as all development is going on there now.

There are a few options:

  1. Use touchesBegan:withEvent, touchesMoved, Ended, Cancelled -- available as override methods on all ASDisplayNodes. This is efficient but doesn't easily handle heuristics like cancelling a tap action if the user drags before lifting it.
  2. Subclass ASControlNode and use addTarget:. This is a very good option as it is highly efficient and has various options available. Note that ASTextNode and ASImageNode are already subclasses of ASControlNode, making it convenient to add tap handlers.
  3. Add a UITapGestureRecognizer in the -didLoad method (don't trigger creating the view early). You can also register a handler with -onDidLoad: and perform the gesture addition in there. However gesture recognizers have some performance overheads. So, suggest only using them for pan recognizers or other cases where ASControlNode is not an easy / convenient architecture.

ASControlNode *gNode;