(1)如果150ms内touch未产生移动,它就把这个事件传递给内部view;
(2)如果150ms内touch产生移动,开始scrolling,不会传递给内部的view。(如当你touch一个table时候,直接scrolling,你touch的那行永远不会highlight。)
(3)如果150ms内touch未产生移动并且UIScrollView开始传递内部的view事件,但是移动足够远的话,且canCancelContentTouches = YES,UIScrollView会调用touchesCancelled方法,cancel掉内部view的事件响应,并开始scrolling。(如当你touch一个table,停止了一会,然后开始scrolling,那一行就首先被highlight,但是随后就不在高亮了)
TestView.h
- @interface
TestView : UIView - {
-
UIImageView *imageView; -
NSTimeInterval touchTimer; //记录touch时间,来控制点击和滑动判断 - }
- @property(nonatomic,
retain) UIImageView *imageView; - @property(nonatomic,
assign) NSTimeInterval touchTimer;
TestView.m
- @implementation
TestView - #pragma
mark - - #pragma
mark Touch Method - @synthesize
imageView; - @synthesize
touchTimer; -
- //thouchesBegan
获取到touch的时间点 - -
(void)touchesBegan:(NSSet *)touches -
withEvent:(UIEvent *)event - {
-
UITouch *touch = [touches anyObject]; -
self.touchTimer = [touch timestamp]; - }
-
-
- //touchesEnded,touch事件完成,根据此时时间点获取到touch事件的总时间,
- -
(void)touchesEnded:(NSSet *)touches -
withEvent:(UIEvent *)event - {
-
UITouch *touch = [touches anyObject]; -
self.touchTimer = [touch timestamp] - self.touchTimer; -
-
NSUInteger tapCount = [touch tapCount]; -
CGPoint touchPoint = [touch locationInView:self]; -
-
//判断单击事件,touch时间和touch的区域 -
if (tapCount == 1 && self.touchTimer <= 3 && CGRectContainsPoint(self.imageView.frame, touchPoint)) -
{ -
//进行单击的跳转等事件 -
} -
- }