ios事件-触摸事件2(手势 和 pointInSide()、hitTest()、touchesBegan()、touchesMoved()、touchesEnded()的关系)
ios事件-触摸事件2(手势 和 pointInSide()、hitTest()、touchesBegan()、touchesMoved()、touchesEnded()、touchesCancelled()的关系)
先看效果图
本文中,凡是看到xxx(),即表示xxx是一个函数或者方法!!!事件分为事件传递和事件响应,其中,事件响应又称事件处理。
具体代码
FindViewViewController的代码如下:
@interface GestureVC : UIViewController
@end
//--------分隔符,分隔.h文件和.m文件-------------
#import "GestureVC.h"
#import "CustomerGesture.h"
#import "GrayView.h"
#import "RedView.h"
#import "BlueView.h"
#import "YellowView.h"
/**1. 手势和pointInSide()以及hitTest()的关系:必须先通过pointInSide()和hitTest()找到的view(即处理事件的view),才能响应view的手势事件。2. 通过hitTest()、pointInSide()找到的view,那么view和它的superView的手势都能响应,但不会响应它的子view的手势。3. 手势的种类(tapGesture、panGesture、swipGesture)怎么分辨出来:手势的touch的4个方法来识别。所以如果你在你自定义的手势里面的重写的touchesBegan: withEvent:方法中不调用[super touchesBegan:touches withEvent:event];时,手势就无法识别,那么手势的监听方法(在本例中为panActiona方法)就不会被调用!4. 手势和view的touch事件的关系:delayTouchBegin、cancelTouchInView*/
@implementation GestureVC- (void)viewDidLoad {self.view.backgroundColor = UIColor.whiteColor;[self createGesture];
}- (void)createGesture {RedView *redView = [[RedView alloc] initWithFrame:CGRectMake(100.f, 100.f, 100.f, 100.f)];[self.view addSubview:redView];CustomerGesture *gesture = [[CustomerGesture alloc] initWithTarget:self action:@selector(panActiona)];//默认情况下,如果手势识别出来了,会cancel掉view的touch事件,即调用view的touchesCancelled:withEvent:方法。[redView addGestureRecognizer:gesture];
}- (void)panActiona {NSLog(@"%s", __func__);
}
@end
CustomerGesture的代码如下:
#import <UIKit/UIKit.h>
/**
CustomerGesture在本文底部的操作场景的讨论中,要么继承UIPanGestureRecognizer,要么继承UITapGestureRecognizer
*/
@interface CustomerGesture : UIPanGestureRecognizer
//@interface CustomerGesture : UITapGestureRecognizer
@end//--------分隔符,分隔.h文件和.m文件-------------
@interface CustomerGesture () {int moveCount;
}
@end
@implementation CustomerGesture- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {moveCount = 0;NSLog(@"%s, moveCount = %d", __func__, moveCount);[super touchesBegan:touches withEvent:event];
}- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {NSLog(@"%s, moveCount = %d", __func__, moveCount);moveCount++;[super touchesMoved:touches withEvent:event];
}- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {NSLog(@"%s, moveCount = %d", __func__, moveCount);[super touchesEnded:touches withEvent:event];
}- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {NSLog(@"%s, moveCount = %d", __func__, moveCount);[super touchesCancelled:touches withEvent:event];
}@end
UIView+Color的代码如下:
@interface UIView (Color)
- (NSString *)bgColorString;
@end//--------分隔符,分隔.h文件和.m文件-------------
@implementation UIView (Color)
- (NSString *)bgColorString {if (self.backgroundColor == [UIColor redColor]) {return @"redColorView";} else if (self.backgroundColor == UIColor.blueColor) {return @"blueColorView";} else if (self.backgroundColor == UIColor.yellowColor) {return @"yellowColorView";} else if (self.backgroundColor == UIColor.lightGrayColor) {return @"lightGrayColorView";}return nil;
}
@end
GrayView的代码如下:
@interface GrayView : UIView
@end//--------分隔符,分隔.h文件和.m文件-------------
#import "UIView+Color.h"@implementation GrayView
- (instancetype)initWithFrame:(CGRect)frame
{self = [super initWithFrame:frame];if (self) {self.backgroundColor = UIColor.lightGrayColor;}return self;
}
//返回的是 点击区域是否在该view的范围内。
//返回YES表示点击区域在当前view中,NO表示点击区域不在当前view中
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {NSLog(@"%@, %s", self.bgColorString, __func__);return [super pointInside:point withEvent:event];
}
//返回的是处理事件的view的实例。
//如果返回自己,表示处理事件的是当前view。返回nil表示当前view及其子view都不处理事件。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {NSLog(@"%@, %s", self.bgColorString, __func__);return [super hitTest:point withEvent:event];
}//scrollView 系统会重写它的super touch:导致不能往上传递,
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {NSLog(@"%@, %s", self.bgColorString, __func__);[super touchesBegan:touches withEvent:event];
}- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {NSLog(@"%@, %s", self.bgColorString, __func__);[super touchesMoved:touches withEvent:event];
}- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {NSLog(@"%@, %s", self.bgColorString, __func__);[super touchesEnded:touches withEvent:event];
}- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {NSLog(@"%@, %s", self.bgColorString, __func__);[super touchesCancelled:touches withEvent:event];
}
@end
BlueView、RedView和YellowView的代码和上面的GrayView的代码相同,只是类名不一样,这里就不贴出来了。
操作场景
- CustomerGesture继承UITapGestureRecognizer, 点击一下红色按钮:,输出结果如下:
redColorView, -[RedView hitTest:withEvent:]
redColorView, -[RedView pointInside:withEvent:]
-[CustomerGesture touchesBegan:withEvent:], moveCount = 0
redColorView, -[RedView touchesBegan:withEvent:]
-[CustomerGesture touchesEnded:withEvent:], moveCount = 0//此时CustomerGesture识别出是点击手势了,就会调用[RedView touchesCancelled:withEvent:]
-[GestureVC panActiona]
redColorView, -[RedView touchesCancelled:withEvent:]
- 事件传递:通过RedView的hitTest()和pointInSide()的调用可知是处理事件的是RedView。
- 事件响应:touchesBegan()的调用顺序是:CustomerGesture->RedView。 当手指离开屏幕时,CustomerGesture的touchesEnded()会被调用。因为这时已经识别出手势为UITapGestureRecognizer类型,所以系统就会调用手势的监听方法(GestureVC类的panActiona方法),接着调用[RedView touchesCancelled:withEvent:],所以RedView的touchesEnded:withEvent:方法不会被调用。
- CustomerGesture继承UITapGestureRecognizer, 在红色按钮的区域内用手指滑动一下,输出结果如下:
redColorView, -[RedView hitTest:withEvent:]
redColorView, -[RedView pointInside:withEvent:]
-[CustomerGesture touchesBegan:withEvent:], moveCount = 0
redColorView, -[RedView touchesBegan:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 0
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 1
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 2
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 3
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 4
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 5
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 6
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 7
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 8
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 9
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 10
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 11
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 12
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 13 //识别出不是点击手势了,所以[CustomerGesture touchesMoved:withEvent:]就不会再被调用了。
redColorView, -[RedView touchesMoved:withEvent:]
redColorView, -[RedView touchesMoved:withEvent:]
redColorView, -[RedView touchesMoved:withEvent:]
redColorView, -[RedView touchesMoved:withEvent:]
redColorView, -[RedView touchesMoved:withEvent:]
redColorView, -[RedView touchesMoved:withEvent:]
redColorView, -[RedView touchesEnded:withEvent:]
- 事件传递::通过RedView的hitTest()和pointInSide()的调用可知是处理事件的是RedView。
- 事件响应:touchesBegan()的调用顺序是:CustomerGesture->RedView。 touchesMoved()的调用顺序是:CustomerGesture->RedView。当系统识别出不是点击手势(即不是UITapGestureRecognizer)了,所以[CustomerGesture touchesMoved:withEvent:]就不会再被调用了,而此时RedView的touchesMoved:withEvent:方法一直被调用(前提是手指还在RedView上滑动)。 当手指离开屏幕时,RedView的touchesEnded()会被调用。
- CustomerGesture继承UIPanGestureRecognizer, 点击一下红色按钮,输出结果如下:
redColorView, -[RedView hitTest:withEvent:]
redColorView, -[RedView pointInside:withEvent:]
-[CustomerGesture touchesBegan:withEvent:]
redColorView, -[RedView touchesBegan:withEvent:]
-[CustomerGesture touchesEnded:withEvent:]
redColorView, -[RedView touchesEnded:withEvent:]
- 事件传递::通过RedView的hitTest()和pointInSide()的调用可知是处理事件的是RedView。
- 事件响应:touchesBegan()的调用顺序是:CustomerGesture->RedView。当手指离开屏幕时, touchesEnded()的调用顺序是:CustomerGesture->RedView。当系统识别出不是滑动手势(即不是UIPanGestureRecognizer)了,所以系统不会调用RedView的touchesCancelled:withEvent:方法,所以RedView的touchesEnded:withEvent:方法会被调用。
- CustomerGesture继承UIPanGestureRecognizer, 在红色按钮的区域内用手指滑动一下,输出结果如下:
redColorView, -[RedView hitTest:withEvent:]
redColorView, -[RedView pointInside:withEvent:]
-[CustomerGesture touchesBegan:withEvent:], moveCount = 0
redColorView, -[RedView touchesBegan:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 0
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 1
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 2
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 3
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 4
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 5
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 6
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 7
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 8
redColorView, -[RedView touchesMoved:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 9 //此时CustomerGesture识别出是滑动手势了,就会调用[RedView touchesCancelled:withEvent:]
-[GestureVC panActiona]
redColorView, -[RedView touchesCancelled:withEvent:]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 10
-[GestureVC panActiona]
-[GestureVC panActiona]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 11
-[GestureVC panActiona]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 12
-[GestureVC panActiona]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 13
-[GestureVC panActiona]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 14
-[GestureVC panActiona]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 15
-[GestureVC panActiona]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 16
-[GestureVC panActiona]
-[CustomerGesture touchesMoved:withEvent:], moveCount = 17
-[GestureVC panActiona]
-[CustomerGesture touchesEnded:withEvent:], moveCount = 18
-[GestureVC panActiona]
- 事件传递::通过RedView的hitTest()和pointInSide()的调用可知是处理事件的是RedView。
- 事件响应:touchesBegan()的调用顺序是:CustomerGesture->RedView。当手指在RedView上滑动时, touchesMoved()的调用顺序是:CustomerGesture->RedView。当系统识别出是滑动手势(即是UIPanGestureRecognizer)了,所以系统会调用RedView的touchesCancelled:withEvent:方法,然后调用手势的监听方法(GestureVC类的panActiona方法)。所以在后面的触摸事件中,RedView的touchesEnded:withEvent:方法不再会被调用,而是调用CustomerGesture的touchesMoved:withEvent:方法和GestureVC的panActiona方法。当手指离开屏幕时,CustomerGesture 的touchesEnded:withEvent:方法和GestureVC的panActiona方法会被调用。
- CustomerGesture继承UIPanGestureRecognizer, 在GestureVC.m中的createGesture()中添加
gesture.cancelsTouchesInView = NO;
,此时GestureVC.m的代码如下:
@implementation GestureVC
- (void)viewDidLoad {self.view.backgroundColor = UIColor.whiteColor;[self createGesture];
}- (void)createGesture {RedView *redView = [[RedView alloc] initWithFrame:CGRectMake(100.f, 100.f, 100.f, 100.f)];[self.view addSubview:redView];CustomerGesture *gesture = [[CustomerGesture alloc] initWithTarget:self action:@selector(panActiona)];//默认情况下,如果手势识别出来了,会cancel掉view的touch事件,即调用view的touchesCancelled:withEvent:方法。//默认为YES。NO表示手势识别出来,不cancel掉view的touch方法的回调gesture.cancelsTouchesInView = NO; //只是添加了这一行代码!!!!!!!!!![redView addGestureRecognizer:gesture];
}
- (void)panActiona {NSLog(@"%s", __func__);
}
@end
此时在红色按钮的区域内用手指滑动一下,输出结果如下:
2019-08-30 15:08:03.245348+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView hitTest:withEvent:]
2019-08-30 15:08:03.245486+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView pointInside:withEvent:]
2019-08-30 15:08:03.246028+0800 E03事件层次分析[12668:8488735] -[CustomerGesture touchesBegan:withEvent:], moveCount = 0
2019-08-30 15:08:03.246345+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView touchesBegan:withEvent:]
2019-08-30 15:08:03.289045+0800 E03事件层次分析[12668:8488735] -[CustomerGesture touchesMoved:withEvent:], moveCount = 0
2019-08-30 15:08:03.289256+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-30 15:08:03.327937+0800 E03事件层次分析[12668:8488735] -[CustomerGesture touchesMoved:withEvent:], moveCount = 1
2019-08-30 15:08:03.328154+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-30 15:08:03.351235+0800 E03事件层次分析[12668:8488735] -[CustomerGesture touchesMoved:withEvent:], moveCount = 2
2019-08-30 15:08:03.351494+0800 E03事件层次分析[12668:8488735] -[GestureVC panActiona]
2019-08-30 15:08:03.351644+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-30 15:08:03.372921+0800 E03事件层次分析[12668:8488735] -[CustomerGesture touchesMoved:withEvent:], moveCount = 3
2019-08-30 15:08:03.373281+0800 E03事件层次分析[12668:8488735] -[GestureVC panActiona]
2019-08-30 15:08:03.373476+0800 E03事件层次分析[12668:8488735] -[GestureVC panActiona]
2019-08-30 15:08:03.373616+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-30 15:08:03.405831+0800 E03事件层次分析[12668:8488735] -[CustomerGesture touchesMoved:withEvent:], moveCount = 4
2019-08-30 15:08:03.406057+0800 E03事件层次分析[12668:8488735] -[GestureVC panActiona]
2019-08-30 15:08:03.406194+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-30 15:08:03.507371+0800 E03事件层次分析[12668:8488735] -[CustomerGesture touchesEnded:withEvent:], moveCount = 5
2019-08-30 15:08:03.507584+0800 E03事件层次分析[12668:8488735] -[GestureVC panActiona]
2019-08-30 15:08:03.507818+0800 E03事件层次分析[12668:8488735] redColorView, -[RedView touchesEnded:withEvent:]
从上面的结果可以看出,当系统虽然识别出是滑动手势(即是UIPanGestureRecognizer)了,但不会调用RedView的touchesCancelled:withEvent:方法,然后调用手势的监听方法(GestureVC类的panActiona方法),接着调用RedView的 touchesMoved:withEvent:方法,直到手指离开屏幕。
- CustomerGesture继承UIPanGestureRecognizer, 在GestureVC.m中的createGesture()中添加
gesture.delaysTouchesBegan = YES;
,此时GestureVC.m的代码如下:
@implementation GestureVC
- (void)viewDidLoad {self.view.backgroundColor = UIColor.whiteColor;[self createGesture];
}- (void)createGesture {RedView *redView = [[RedView alloc] initWithFrame:CGRectMake(100.f, 100.f, 100.f, 100.f)];[self.view addSubview:redView];CustomerGesture *gesture = [[CustomerGesture alloc] initWithTarget:self action:@selector(panActiona)];//默认为NO。如果为YES,无论什么手势(比如UITapGestureRecognizer或者UIPanGestureRecognizer),就阻止view的touchesBegan方法的调用(识别)gesture.delaysTouchesBegan = YES; //只有这一行代码被添加!!!!!!![redView addGestureRecognizer:gesture];
}- (void)panActiona {NSLog(@"%s", __func__);
}
@end
此时在红色按钮的区域内用手指滑动一下,输出结果如下:
2019-08-31 12:31:42.318117+0800 E03事件层次分析[26416:9622148] redColorView, -[RedView hitTest:withEvent:]
2019-08-31 12:31:42.318357+0800 E03事件层次分析[26416:9622148] redColorView, -[RedView pointInside:withEvent:]
2019-08-31 12:31:42.319321+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesBegan:withEvent:], moveCount = 0
2019-08-31 12:31:42.362970+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesMoved:withEvent:], moveCount = 0
2019-08-31 12:31:42.385229+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesMoved:withEvent:], moveCount = 1
2019-08-31 12:31:42.407373+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesMoved:withEvent:], moveCount = 2
2019-08-31 12:31:42.407749+0800 E03事件层次分析[26416:9622148] -[GestureVC panActiona]
2019-08-31 12:31:42.429652+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesMoved:withEvent:], moveCount = 3
2019-08-31 12:31:42.429888+0800 E03事件层次分析[26416:9622148] -[GestureVC panActiona]
2019-08-31 12:31:42.430015+0800 E03事件层次分析[26416:9622148] -[GestureVC panActiona]
2019-08-31 12:31:42.452773+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesMoved:withEvent:], moveCount = 4
2019-08-31 12:31:42.453046+0800 E03事件层次分析[26416:9622148] -[GestureVC panActiona]
2019-08-31 12:31:42.474992+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesMoved:withEvent:], moveCount = 5
2019-08-31 12:31:42.475262+0800 E03事件层次分析[26416:9622148] -[GestureVC panActiona]
2019-08-31 12:31:42.541643+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesMoved:withEvent:], moveCount = 6
2019-08-31 12:31:42.541836+0800 E03事件层次分析[26416:9622148] -[GestureVC panActiona]
2019-08-31 12:31:42.576170+0800 E03事件层次分析[26416:9622148] -[CustomerGesture touchesEnded:withEvent:], moveCount = 7
2019-08-31 12:31:42.576434+0800 E03事件层次分析[26416:9622148] -[GestureVC panActiona]
从上面的结果可以看出,当系统虽然识别出是滑动手势(即是UIPanGestureRecognizer)了,就会调用手势的监听方法(GestureVC类的panActiona方法)。在整个事件序列中(一个事件序列是:手机触摸屏幕,接着在屏幕滑动,最后手指离开屏幕),RedView的touches开头的4个方法都不会被调用!
- CustomerGesture继承UIPanGestureRecognizer, 在GestureVC.m中的createGesture()中同时添加
gesture.delaysTouchesBegan = YES;
和gesture.cancelsTouchesInView = NO;
,此时GestureVC.m的代码如下:
@implementation GestureVC
- (void)viewDidLoad {self.view.backgroundColor = UIColor.whiteColor;[self createGesture];
}- (void)createGesture {RedView *redView = [[RedView alloc] initWithFrame:CGRectMake(100.f, 100.f, 100.f, 100.f)];[self.view addSubview:redView];CustomerGesture *gesture = [[CustomerGesture alloc] initWithTarget:self action:@selector(panActiona)];//默认情况下,如果手势识别出来了,会cancel掉view的touch事件,即调用view的touchesCancelled:withEvent:方法。//默认为NO。如果为YES,无论什么手势(比如UITapGestureRecognizer或者UIPanGestureRecognizer),就阻止view的touchesBegan方法的调用(识别)gesture.delaysTouchesBegan = YES;//默认为YES。NO表示手势识别出来,不cancel掉view的touch方法的回调gesture.cancelsTouchesInView = NO;[redView addGestureRecognizer:gesture];
}- (void)panActiona {NSLog(@"%s", __func__);
}
@end
此时在红色按钮的区域内用手指滑动一下,输出结果如下:
2019-08-31 12:35:35.657777+0800 E03事件层次分析[26481:9629016] redColorView, -[RedView hitTest:withEvent:]
2019-08-31 12:35:35.657978+0800 E03事件层次分析[26481:9629016] redColorView, -[RedView pointInside:withEvent:]
2019-08-31 12:35:35.658789+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesBegan:withEvent:], moveCount = 0
2019-08-31 12:35:35.702652+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesMoved:withEvent:], moveCount = 0
2019-08-31 12:35:35.724521+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesMoved:withEvent:], moveCount = 1
2019-08-31 12:35:35.747421+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesMoved:withEvent:], moveCount = 2
2019-08-31 12:35:35.748178+0800 E03事件层次分析[26481:9629016] -[GestureVC panActiona]
2019-08-31 12:35:35.748529+0800 E03事件层次分析[26481:9629016] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-31 12:35:35.770069+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesMoved:withEvent:], moveCount = 3
2019-08-31 12:35:35.770455+0800 E03事件层次分析[26481:9629016] -[GestureVC panActiona]
2019-08-31 12:35:35.770726+0800 E03事件层次分析[26481:9629016] -[GestureVC panActiona]
2019-08-31 12:35:35.771042+0800 E03事件层次分析[26481:9629016] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-31 12:35:35.791819+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesMoved:withEvent:], moveCount = 4
2019-08-31 12:35:35.792046+0800 E03事件层次分析[26481:9629016] -[GestureVC panActiona]
2019-08-31 12:35:35.792181+0800 E03事件层次分析[26481:9629016] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-31 12:35:35.815099+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesMoved:withEvent:], moveCount = 5
2019-08-31 12:35:35.815475+0800 E03事件层次分析[26481:9629016] -[GestureVC panActiona]
2019-08-31 12:35:35.815723+0800 E03事件层次分析[26481:9629016] redColorView, -[RedView touchesMoved:withEvent:]
2019-08-31 12:35:35.896018+0800 E03事件层次分析[26481:9629016] -[CustomerGesture touchesEnded:withEvent:], moveCount = 6
2019-08-31 12:35:35.896272+0800 E03事件层次分析[26481:9629016] -[GestureVC panActiona]
2019-08-31 12:35:35.896564+0800 E03事件层次分析[26481:9629016] redColorView, -[RedView touchesEnded:withEvent:]
从上面的结果可以看出,当系统虽然识别出是滑动手势(即是UIPanGestureRecognizer)了,就会调用手势的监听方法(GestureVC类的panActiona方法),因为GestureVC.m中添加了gesture.cancelsTouchesInView = NO;
,即告诉系统说手势识别出来后,不要cancel掉view的touch方法的回调,所以RedView的touchesMoved:withEvent:方法和touchesEnded:withEvent:方法还是会被调用。
写的有些乱,如果你能看到这里,那你挺厉害的。
ios事件-触摸事件2(手势 和 pointInSide()、hitTest()、touchesBegan()、touchesMoved()、touchesEnded()的关系)相关推荐
- iOS 一一 触摸事件和手势
iOS触摸事件和手势 文章出处:http://www.jianshu.com/p/cb0314b72883 在iOS中,触摸表示用户手指触击屏幕及在屏幕上移动时,系统不断发送给应用程序对象,一个UIT ...
- ios事件-触摸事件3(UIButton 和 pointInSide()、hitTest()、touchesBegan()、touchesMoved()、touchesEnded()的关系)
ios事件-触摸事件3(UIButton 和 pointInSide().hitTest().touchesBegan().touchesMoved().touchesEnded().touchesC ...
- iOS开发触摸事件的传递
1. iOS中的三种事件类型 触摸事件.加速计事件.远程事件. 触摸事件:通过触摸.手势进行触发(例如手指点击.缩放) 加速计事件:通过加速器进行触发(例如手机晃动,典型应用是微信摇一摇) 远程事件: ...
- IOS中触摸事件学习
IOS中触摸事件学习 1. 事件的声明周期 2. 系统相应阶段 3. APP响应阶段 4. 触摸.事件.响应者 4.1 UITouch(触摸) 4.2 UIEvent(事件真身) 4.3 UIResp ...
- iOS中触摸事件传递和响应原理
系统响应阶段 1.手指触碰屏幕,屏幕感受到触摸后,将事件交由IOKit来处理. 2.IOKIT将触摸事件封装成IOHIDEvent对象,并通过mach port传递给SpringBoard进程. ma ...
- iOS:触摸事件、手势识别、摇晃事件、耳机线控
概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事件(手势操作).运动事件. ...
- iOS UITouch触摸与UIGesture手势.01.事件、触摸(touch)事件
一.iOS事件: 1.事件:事件就是当你在手机上点击手机屏幕.滑动手机翻面.摇动手机的时候,手机做出一些反应,对应的在应用程序里实现了某些代码的某些功能,完成这个过程就是一个事件. 2.iOS事件类型 ...
- ScrollView的上下联动事件 触摸事件传递机制
注意事项:1.当返回值为false的时候,触摸事件向下或者向子view传递: 2.当返回时间为true时:触摸事件不向下执行 常用事件的方法: dispatchTouchEvent(Acitivity ...
- IOS UITouch 触摸事件,UIResponder 的作用
IOS 中事件响应皆是通过UIResponder.我们可以执行UIResponder协议响应事件.这里我们用UIViewController做示例,UIViewController默认实现UIResp ...
最新文章
- 自动驾驶软件工程课程之SLAM(2)
- 从Blue Pill、硬件虚拟化谈安全防护完备性上的一个小原则
- 2014百度之星资格赛 1001:Energy Conversion(水题,逻辑题)
- 案例 | 用pdpipe搭建pandas数据分析流水线
- Hive 1.1.1 启动错误
- CCS3的过渡、变换、动画以及响应式布局、弹性布局
- 前端学习(1290):nodejs模块化的开发导出另一种方式
- python函数的嵌套和递归_Python通过递归函数输出嵌套列表元素
- DDD-上下文映射图
- 电脑耳机声音小怎么调大_湘乡电脑耳机怎么样,IP话机推荐
- 关于word中如何生成自动目录以及页码编排
- python布尔值使用_Python布尔值--True和False
- php中关于js保存文件至本地的问题
- 堪称懒人神器?Reno5新配色一键美妆功能,素颜出镜也不怕
- H3C交换机版本升级
- 【模板】FHQ Treap
- 人工智能(AI)是如何处理数据的?
- 你能把压缩过的js代码重新美化成更可读的形式吗
- 求求你!不要在网上乱拷贝代码了
- 电商黑马,集体倒在2019!