IOS(UI)_手勢1

手勢_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(@"無法識別的手勢");
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章