[ASControlNode] hitTestDebug tool refactoring + comments:wq

This commit is contained in:
Hannah Troisi
2016-04-10 00:51:36 -07:00
parent 7fa810c77f
commit a6f779a7fe
2 changed files with 29 additions and 15 deletions

View File

@@ -467,8 +467,7 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
// Even if our parents don't have clipsToBounds set and would allow us to display the debug overlay, UIKit event delivery (hitTest:) // Even if our parents don't have clipsToBounds set and would allow us to display the debug overlay, UIKit event delivery (hitTest:)
// will not search sub-hierarchies if one of our parents does not return YES for pointInside:. In such a scenario, hitTestSlop // will not search sub-hierarchies if one of our parents does not return YES for pointInside:. In such a scenario, hitTestSlop
// may not be able to expand the tap target as much as desired without also setting some hitTestSlop on the limiting parents. // may not be able to expand the tap target as much as desired without also setting some hitTestSlop on the limiting parents.
CGRect originalRect = UIEdgeInsetsInsetRect(self.bounds, [self hitTestSlop]); CGRect intersectRect = UIEdgeInsetsInsetRect(self.bounds, [self hitTestSlop]);
CGRect intersectRect = originalRect;
UIRectEdge clippedEdges = UIRectEdgeNone; UIRectEdge clippedEdges = UIRectEdgeNone;
UIRectEdge clipsToBoundsClippedEdges = UIRectEdgeNone; UIRectEdge clipsToBoundsClippedEdges = UIRectEdgeNone;
CALayer *layer = self.layer; CALayer *layer = self.layer;
@@ -480,18 +479,33 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
while (intersectSuperlayer && ![intersectSuperlayer.delegate respondsToSelector:@selector(contentOffset)]) { while (intersectSuperlayer && ![intersectSuperlayer.delegate respondsToSelector:@selector(contentOffset)]) {
// Get our parent's tappable bounds. If the parent has an associated node, consider hitTestSlop, as it will extend its pointInside:. // Get our parent's tappable bounds. If the parent has an associated node, consider hitTestSlop, as it will extend its pointInside:.
CGRect parentHitRect = intersectSuperlayer.bounds; CGRect parentHitRect = intersectSuperlayer.bounds;
BOOL parentClipsToBounds = intersectSuperlayer.masksToBounds; BOOL parentClipsToBounds = NO;
ASDisplayNode *parentNode = ASLayerToDisplayNode(intersectSuperlayer); ASDisplayNode *parentNode = ASLayerToDisplayNode(intersectSuperlayer);
if (parentNode && !parentClipsToBounds) { if (parentNode) {
parentHitRect = UIEdgeInsetsInsetRect(parentHitRect, [parentNode hitTestSlop]); UIEdgeInsets parentSlop = [parentNode hitTestSlop];
// if parent has a hitTestSlop as well, we need to account for the fact that events will be routed towards us in that area too.
if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, parentSlop)) {
parentClipsToBounds = parentNode.clipsToBounds;
// if the parent is clipping, this will prevent us from showing the overlay outside that area.
// in this case, we will make the overlay smaller so that the special highlight to indicate the overlay
// cannot accurately display the true tappable area is shown.
if (!parentClipsToBounds) {
parentHitRect = UIEdgeInsetsInsetRect(parentHitRect, [parentNode hitTestSlop]);
}
}
} }
// Convert our current rectangle to parent coordinates, and intersect with the parent's hit rect. // Convert our current rectangle to parent coordinates, and intersect with the parent's hit rect.
CGRect intersectRectInParentCoordinates = [intersectSuperlayer convertRect:intersectRect fromLayer:intersectLayer]; CGRect intersectRectInParentCoordinates = [intersectSuperlayer convertRect:intersectRect fromLayer:intersectLayer];
intersectRect = CGRectIntersection(parentHitRect, intersectRectInParentCoordinates); intersectRect = CGRectIntersection(parentHitRect, intersectRectInParentCoordinates);
if (parentClipsToBounds) { if (!CGSizeEqualToSize(parentHitRect.size, intersectRectInParentCoordinates.size)) {
if (!CGSizeEqualToSize(parentHitRect.size, intersectRectInParentCoordinates.size)) { clippedEdges = [self setEdgesOfIntersectionForChildRect:intersectRectInParentCoordinates
clipsToBoundsClippedEdges = [self setEdgesOfIntersectionForChildRect:intersectRectInParentCoordinates parentRect:parentHitRect rectEdge:clipsToBoundsClippedEdges]; parentRect:parentHitRect rectEdge:clippedEdges];
if (parentClipsToBounds) {
clipsToBoundsClippedEdges = [self setEdgesOfIntersectionForChildRect:intersectRectInParentCoordinates
parentRect:parentHitRect rectEdge:clipsToBoundsClippedEdges];
} }
} }
@@ -504,10 +518,7 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
UIColor *fillColor = [[UIColor greenColor] colorWithAlphaComponent:0.4]; UIColor *fillColor = [[UIColor greenColor] colorWithAlphaComponent:0.4];
// determine which edges were clipped // determine which edges were clipped
if (!CGSizeEqualToSize(originalRect.size, finalRect.size)) { if (clippedEdges != UIRectEdgeNone) {
clippedEdges = [self setEdgesOfIntersectionForChildRect:originalRect parentRect:finalRect rectEdge:clippedEdges];
const CGFloat borderWidth = 2.0; const CGFloat borderWidth = 2.0;
UIColor *superhitTestSlopClipsBorderColor = [UIColor colorWithRed:30/255.0 green:90/255.0 blue:50/255.0 alpha:0.7]; UIColor *superhitTestSlopClipsBorderColor = [UIColor colorWithRed:30/255.0 green:90/255.0 blue:50/255.0 alpha:0.7];
UIColor *superClipsToBoundsBorderColor = [[UIColor orangeColor] colorWithAlphaComponent:0.8]; UIColor *superClipsToBoundsBorderColor = [[UIColor orangeColor] colorWithAlphaComponent:0.8];

View File

@@ -12,9 +12,12 @@
@interface ASControlNode (Debugging) @interface ASControlNode (Debugging)
/** /**
Class method to enable a visualization overlay of the tapable area on the ASControlNode. For app debugging purposes only. Class method to enable a visualization overlay of the tappable area on the ASControlNode. For app debugging purposes only.
Overlay = translucent green color, edges clipped by hitTestDebug of any parent in the hierarchy = dark green bordered edge, NOTE: GESTURE RECOGNIZERS, (including tap gesture recognizers on a control node) WILL NOT BE VISUALIZED!!!
edges clipped by clipToBounds = YES of any parent in the hierarchy = orange bordered edge. Overlay = translucent GREEN color,
edges that are clipped by the tappable area of any parent (their bounds + hitTestSlop) in the hierarchy = DARK GREEN BORDERED EDGE,
edges that are clipped by clipToBounds = YES of any parent in the hierarchy = ORANGE BORDERED EDGE (may still receive touches beyond
overlay rect, but can't be visualized).
@param enable Specify YES to make this debug feature enabled when messaging the ASControlNode class. @param enable Specify YES to make this debug feature enabled when messaging the ASControlNode class.
*/ */
+ (void)setEnableHitTestDebug:(BOOL)enable; + (void)setEnableHitTestDebug:(BOOL)enable;