手勢_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(@"無法識別的手勢");
}