UIScrollView-isTracking delaysContentTouches cancancancelcontenttouches,
UIScrollView has a BOOL-type tracking attribute to return whether the user has reached the content and intends to Start scrolling. From this attribute, we will explore how UIScrollView works:
When you touch the UIScrollView content with your finger, the following actions are triggered:
- Intercept touch events
Tracking attribute changed to YES
A built-in timer starts to take effect and is used to monitor whether finger movement occurs during extremely short event intervals.
Case1: When the finger is moved within the detected time interval, UIScrollView triggers rolling by itself, and the tracking attribute changes to NO. Even if there is one when the finger is touched (it can respond to the touch event) the internal control will no longer respond to the touch event.
Case2: When the finger does not move within the detected time interval, the tracking attribute remains YES. If there is an internal control under the finger touch (which can respond to the touch event, the Touch event is passed to the control for processing.
There is a sliding menu bar on the top of many news apps. The main model may be a UIScrollView consisting of multiple UIButton controls. When you operate, if the finger is quickly crossed, you will find that UIButton does not trigger any touch event of the UIButton even if the finger is touched, Which is case1 mentioned above; the UIButton touch event is triggered only when your fingers are slowly crossed or not moved at all. This is the case of case2.
The working principle above is actually a property switch to control: delaysContentTouches. The default value is YES. If it is set to NO, the touch event is always passed to the internal control NO matter how fast the finger moves. Setting it to NO may affect the scrolling function of UIScrollView.
Let's look at canCencelContentTouches, another BOOL type attribute. It literally means "you can cancel content touch". The default value is YES. The explanation in this document is as follows:
A Boolean value that controls whether touches in the content view always lead to tracking.
If the value of this property is YES and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view Details es a touchesCancelled: withEvent: message and the scroll view handles the touch as a scroll. if the value of this property is NO, the scroll view does not scroll regardless of finger movement once the content view starts tracking.
The Translation into Chinese is roughly as follows:
This BOOL type value controls whether the touch in the content view always triggers tracking)
If the value of the value is YES and the trace is directed to a content control, the content control receives a touchesCancelled: withEvent: message, scroll view uses this touch as a scroll. If the value is NO, once the content view starts tracking (tracking = YES), scrollView does not scroll regardless of whether the finger moves.
To put it simply, if YES, the user will wait for the next action. If the user moves his finger to a certain distance, the operation will be processed as a scroll and start rolling, send a touchesCancelled: withEvent: Message to the content control, which is processed by the control. If it is NO, it will not wait for the user's next action and will never trigger scrollView scrolling.
You can use a piece of code to verify and observe, define a MyScrollView inherited from UIScrollView, A MyButton inherited from UIButton, and then rewrite some methods:
MyScrollView. m
- (BOOL)touchesShouldCancelInContentView:(UIView *)view{ [super touchesShouldCancelInContentView:view]; NSLog(@"touchesShouldCancelInContentView"); return YES;}- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ [super touchesCancelled:touches withEvent:event]; NSLog(@"touchesCancelled");}
MyButton. m
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ [super touchesCancelled:touches withEvent:event]; NSLog(@"【Button's touch cancelled】");}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [super touchesBegan:touches withEvent:event]; NSLog(@"【Button's touch began】");}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ [super touchesMoved:touches withEvent:event]; NSLog(@"【Button's touch moved】");}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ [super touchesEnded:touches withEvent:event]; NSLog(@"【Button's touch ended】");}
In fact, a flag is printed when each method is executed. When the canCencelContentTouches value is YES, the user can touch and move his finger again:
[Button's touch began]
[Button's touch moved]
......
[Button's touch moved]
TouchesShouldCancelInContentView
[Button's touch canceled]
When the canCencelContentTouches value is NO, you can touch and move your finger to release it:
[Button's touch began]
[Button's touch moved]
......
[Button's touch moved]
[Button's touch ended]
Reference link:
Http://www.jianshu.com/p/9436c9a2cd1e
Http://blog.csdn.net/opentogether/article/details/52223878