mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-14 08:03:59 +00:00
Respect hitTestSlop when determining if a tracked touch is inside for ASControlNode (#2896)
This commit is contained in:
parent
30194fe41f
commit
f52bc786c0
@ -63,6 +63,14 @@ id<NSCopying> _ASControlNodeEventKeyForControlEvent(ASControlNodeEvent controlEv
|
|||||||
*/
|
*/
|
||||||
void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, void (^block)(ASControlNodeEvent anEvent));
|
void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, void (^block)(ASControlNodeEvent anEvent));
|
||||||
|
|
||||||
|
/**
|
||||||
|
@abstract Returns the expanded bounds used to determine if a touch is considered 'inside' during tracking.
|
||||||
|
@param controlNode A control node.
|
||||||
|
@result The expanded bounds of the node.
|
||||||
|
*/
|
||||||
|
CGRect _ASControlNodeGetExpandedBounds(ASControlNode *controlNode);
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation ASControlNode
|
@implementation ASControlNode
|
||||||
@ -158,7 +166,7 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
|||||||
BOOL dragIsInsideBounds = [self pointInside:touchLocation withEvent:nil];
|
BOOL dragIsInsideBounds = [self pointInside:touchLocation withEvent:nil];
|
||||||
|
|
||||||
// Update our highlighted state.
|
// Update our highlighted state.
|
||||||
CGRect expandedBounds = CGRectInset(self.view.bounds, kASControlNodeExpandedInset, kASControlNodeExpandedInset);
|
CGRect expandedBounds = _ASControlNodeGetExpandedBounds(self);
|
||||||
BOOL dragIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
|
BOOL dragIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
|
||||||
self.touchInside = dragIsInsideExpandedBounds;
|
self.touchInside = dragIsInsideExpandedBounds;
|
||||||
self.highlighted = dragIsInsideExpandedBounds;
|
self.highlighted = dragIsInsideExpandedBounds;
|
||||||
@ -216,7 +224,7 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
|||||||
[self endTrackingWithTouch:theTouch withEvent:event];
|
[self endTrackingWithTouch:theTouch withEvent:event];
|
||||||
|
|
||||||
// Send the appropriate touch-up control event.
|
// Send the appropriate touch-up control event.
|
||||||
CGRect expandedBounds = CGRectInset(self.view.bounds, kASControlNodeExpandedInset, kASControlNodeExpandedInset);
|
CGRect expandedBounds = _ASControlNodeGetExpandedBounds(self);
|
||||||
BOOL touchUpIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
|
BOOL touchUpIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
|
||||||
|
|
||||||
[self sendActionsForControlEvents:(touchUpIsInsideExpandedBounds ? ASControlNodeEventTouchUpInside : ASControlNodeEventTouchUpOutside)
|
[self sendActionsForControlEvents:(touchUpIsInsideExpandedBounds ? ASControlNodeEventTouchUpInside : ASControlNodeEventTouchUpOutside)
|
||||||
@ -428,6 +436,10 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGRect _ASControlNodeGetExpandedBounds(ASControlNode *controlNode) {
|
||||||
|
return CGRectInset(UIEdgeInsetsInsetRect(controlNode.view.bounds, controlNode.hitTestSlop), kASControlNodeExpandedInset, kASControlNodeExpandedInset);
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - For Subclasses
|
#pragma mark - For Subclasses
|
||||||
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)touchEvent
|
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)touchEvent
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user