UITouch 对象用于位置、 大小、 运动和一根手指在屏幕上为某一特定事件的力度。触摸的力度是从开始在 iOS 9 支持 3D 的触摸的设备上可用。你可以通过UIEvent对象传递给响应者对象访问。一个UITouch对象包括访问器:
//引起触摸的视图或Window. @property(nullable,nonatomic,readonly,strong) UIWindow *window @property(nullable,nonatomic,readonly,strong) UIView *view //触摸在视图或Window的位置坐标. - (CGPoint)locationInView:(nullable UIView *)view //触摸的半径. @property(nonatomic,readonly) CGFloat altitudeAngle //触摸的力度(支持iOS9.0以上) @property(nonatomic,readonly) CGFloat force
UITouch对象还包含一个指示触摸发生时间的时间戳,一个整数表示用户点击屏幕的次数,在触摸阶段以常量的形式描述触摸是否开始,移动,或结束,或者是否为系统取消触摸。一个触摸对象始终存留一个触摸序列。处理事件时,永远不会保留一个触摸对象。如果你需要从一个触摸阶段到另一个阶段保留有关触摸信息,就应该复制该信息。触摸的 gestureRecognizers 属性包含当前正在处理的触摸手势识别器。每个手势识别器是 UIGestureRecognizer 具体子类的一个实例。下面是一个实例我在ViewController定义2个UIVIEW实例对象
@interface ViewController : UIViewController @property (nonatomic, strong) UIView *viewA; @property (nonatomic, strong) UIView *viewB; @end
然后
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.viewA =[[UIView alloc] initWithFrame:CGRectMake(10, 30, 48, 48)]; self.viewA.backgroundColor = [UIColor blackColor]; [self.view addSubview:self.viewA]; self.viewB =[[UIView alloc] initWithFrame:CGRectMake(10, 100, 48, 48)]; self.viewB.backgroundColor = [UIColor redColor]; [self.view addSubview:self.viewB]; NSLog(@"viewA:%@ \n viewB:%@ \n window:%@",self.viewA,self.viewB,[[[UIApplication sharedApplication] windows] objectAtIndex:0]); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event { // NSLog(@"%@",[touches anyObject]); UITouch *touctObj = [touches anyObject]; NSLog(@"touch:%@ \n view:%@ \n window:%@",touctObj,[touctObj view],[touctObj window]); }