mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-06 22:34:04 +08:00
Update debug-tool-hit-test-slop.md
This commit is contained in:
@@ -5,14 +5,28 @@ permalink: /docs/debug-tool-hit-test-slop.html
|
||||
next: debug-tool-ASRangeController.html
|
||||
---
|
||||
|
||||
## Visualize tappable areas on ASControlNodes
|
||||
### Description
|
||||
This debug feature adds a semi-transparent neon green highlight overlay on any ASControlNodes that have a `target:action:` pair added. The tappable range is defined as the ASControlNode’s frame + its hitTestSlop (UIEdgeInsets used by the ASControlNode to extend it’s tappable range).
|
||||
##Visualize tappable areas on ASControlNodes##
|
||||
This debug feature adds a semi-transparent highlight overlay on any ASControlNodes containing a `target:action:` pair or gesture recognizer. The tappable range is defined as the ASControlNode’s frame + its `.hitTestSlop` `UIEdgeInsets`. Hit test slop is a unique feature of `ASControlNode` that allows it to extend its tappable range.
|
||||
|
||||
**This debug feature is useful for quickly visualizing an ASControlNode's tappable range.** In the screenshot below, you can quickly see 3 things: (1) The tappable area for the avatar image overlaps the username’s tappable area. In this case, the user avatar image is on top in the view hierarchy and is capturing some touches that should go to the username. (2) It would probably make sense to expand the hitTestSlop for the username to allow the user to more easily hit it. (3) I’ve accidentally set the hitTestSlop’s UIEdgeInsets to be positive instead of negative for the photo likes count label. It’s going to be hard for a user to tap the smaller target.
|
||||
**This debug feature is useful for quickly visualizing ASControlNode's tappable range**
|
||||
|
||||
In the screenshot below, you can quickly see that
|
||||
<ul>
|
||||
<li>The tappable area for the avatar image overlaps the username’s tappable area. In this case, the user avatar image is on top in the view hierarchy and is capturing some touches that should go to the username.</li>
|
||||
<li>It would probably make sense to expand the `.hitTestSlop` for the username to allow the user to more easily hit it.</li>
|
||||
<li>I’ve accidentally set the hitTestSlop’s UIEdgeInsets to be positive instead of negative for the photo likes count label. It’s going to be hard for a user to tap the smaller target.</li>
|
||||
</ul>
|
||||
|
||||

|
||||
### Usage
|
||||
In your AppDelegate, (1) import `AsyncDisplayKit+Debug.h` and (2) at the top of `didFinishLaunchingWithOptions:` enable this feature by adding` [ASControlNode setEnableHitTestDebug:YES];` Make sure to call this method before initializing any ASControlNodes (including ASButtonNodes, ASImageNodes, and ASTextNodes).
|
||||
### Limitations
|
||||
This only works for ASControlNodes’s with `addTarget:action:` pairs added. **It will not work with gesture recognizers.**
|
||||
|
||||
###Clipping###
|
||||
|
||||
A _green_ border on the edge(s) of the highlight overlay indicates that that edge of the tapable area is restricted by one of it's superview's tapable areas. An _orange_ border on the edge(s) of the highlight overlay indicates that that edge of the tapable area is clipped by .clipsToBounds of a parent in its hierarchy.
|
||||
|
||||
###Usage###
|
||||
In your `AppDelegate.m` file,
|
||||
<ul>
|
||||
<li>import `AsyncDisplayKit+Debug.h`</li>
|
||||
<li>add `[ASControlNode setEnableHitTestDebug:YES];` at the top of your `didFinishLaunchingWithOptions:` method</li>
|
||||
</ul>
|
||||
Make sure to call this method before initializing any ASControlNodes - including ASButtonNodes, ASImageNodes, and ASTextNodes.
|
||||
|
||||
Reference in New Issue
Block a user