iphone几个手势操作(收集)

 1. 获取所有触摸信息
        NSMutableSet * mutableTouches = [touches mutableCopy];
        //或者
        NSSet *allTouches = [event allTouches];
 
  2.判断是多触点还是单触点
        NSSet *allTouches = [event allTouches];
 
        [allTouches count] = 1  为单触点
        [allTouches count] >= 2  为多触点。同时可以知道是几个触点
 
        //第一触点
            UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
        //第二触点
            UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
        //第三触点
            UITouch *touch = [[allTouches allObjects] objectAtIndex:2];
 

        判定触摸点是单击还是双击 [touch tapCount] 决定

/

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    //单击,双击处理
    NSSet *allTouches = [event allTouches];
    switch ([allTouches count]) {
        case 1: {
            UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
            switch ([touch tapCount]) {
                case 1: //单击
                    break;
                case 2: //双击
                    break;
                    
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
   
    
}

//计算两个点之间的距离函数
- (CGFloat)distanceBetweenTowPoints:(CGPoint)fromPoint toPoint:(CGPoint)toPoint {
    float x = toPoint.x - fromPoint.x;
    float y = toPoint.y - fromPoint.y;
    return sqrt(x * x + y * y);
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //两个指头的分开,合拢手势
    NSSet * allTouches = [event allTouches];
    switch ([allTouches count]) {
        case 1: //单点触摸
            break;
        case 2:  {//两点触摸
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            
            beginDistance = [self distanceBetweenTowPoints:[touch1 locationInView:[self view]] toPoint:[touch2 locationInView:[self view]]];
        }
            break;
            
        default:
            break;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    //两个指头移动时,判断是分开还是合拢
    NSSet *allTouches = [event allTouches];
    switch ([allTouches count]) {
        case 1:
            break;
        case 2: {
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            
            CGFloat endDistance = [self distanceBetweenTowPoints:[touch1 locationInView:[self view]] toPoint:[touch2 locationInView:[self view]]];
            
            if (beginDistance > endDistance) {
                //合拢
            }
            else {
                //分开
            }
        }
            break;
            
        default:
            break;
    }
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值