手势_1
set集合中不能存放相同的对象。它是一组单值对象的集合,并且存入集合中的数据是无序的。
手指触碰屏幕:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
NSLog(@"手指触碰屏幕");
//获取对象
UITouch *touch = [touches anyObject];
//对象个数
NSLog(@"touch.tapCount = %lu",touch.tapCount);
//显示触摸开始和最后改变的时间
NSLog(@"timestamp =%f",touch.timestamp);
NSLog(@"%lu根手指",event.allTouches.count);
// CGPoint point = [touch locationInView:self.view];
// NSLog(@"point = %@",[NSValue valueWithCGPoint:point]);
/*
返回所有触摸对象
*/
NSSet *set = event.allTouches;
for (UITouch *t in set)
{
//找到手指在屏幕的位置
CGPoint point = [t locationInView:self.view];
NSLog(@"point = %@",[NSValue valueWithCGPoint:point]);
}
}
手指在屏幕上移动:
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
NSLog(@"手指在屏幕上移动");
NSSet *set = event.allTouches;
for (UITouch *t in set)
{
CGPoint point = [t locationInView:self.view];
NSLog(@"point = %@",[NSValue valueWithCGPoint:point]);
}
}
手指离开屏幕:
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
NSLog(@"手指离开屏幕");
}
无法识别的手势:
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
NSLog(@"无法识别的手势");
}