General principle:

UIScrollView is actually changing the origin coordinates as it scrolls. When a finger touches, the Scroll View temporarily intercepts the touch event, using a timer. If no finger movement event occurs after the timer expires, the Scroll View sends tracking Events to the clicked subview. If a movement event occurs before the timer expires, the Scroll View will unscroll tracking by itself.

First understand the UIScrollView for the touch event receiving and processing principle:

UIScrollView should override the hitTest method and always return itself. So all touch events go into itself. The internal touch event detects whether the event is relevant to it and either handles or removes the event passed to the internal view.

To detect whether a touch is processed or passed, UIScrollView generates a timer when a touch occurs.

If the touch does not move within 150ms, it passes this event to the internal view

If the touch moves within 150ms, it starts scrolling and is not passed to the internal view. (For example, when you touch a table, scrolling directly; your touch row never highlights.)

CanCancelContentTouches = YES if the touch hasn’t moved within 150ms and UIScrollView starts transmitting internal View events but moves far enough The UIScrollView calls the touchesCancelled method to cancel the internal view’s event response and start scrolling. (For example, when you touch a table, stop scrolling for a while and start scrolling, the row is highlighted first but not later.)

Note:

HitTest is useful when adding a mask to a view without affecting operations on the view below it.

Add the following function to a UIView subclass, the mask class.

-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event

{

UIView *hitView = [super hitTest:point withEvent:event];

if (hitView == self)

{

return nil;

}

else

{

return hitView;

}

}