ios开发之多点触摸

 一般,Tap、pinch,pan、swipe只是一个简单的单个触摸,它有一定的局限性,所以多点触摸诞生了~为实现多点触摸,首先得做下列事情

  • 设置view的属性multipleTouchEnabled = YES(注意了。。。默认值是NO);
  • 使用CFDictionaryRef来保存触摸过程的参数 

对于使用多点触摸处理事件,你必须频繁地存储以后进行触摸比较的触摸状态。例如,你要比较每个触摸的结束点位置和原始位置,你可以在touchesBegan:withEvent: 方法中获取每个触摸的原始位置(使用locationInView:方法),然后存储在CFDictionaryRef对象中,使用UITouch对象地址作为KEY。然后你可以在touchesEnded:withEvent: 方法中取出原始点,和当前点进行比较。

需要注意的是这里使用CFDictionaryRef对象而不是NSDitionary对象,因为UITouch类没有实现NSCopying协议。

复制代码
 1 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 2      [self cacheBeginPointForTouches:touches];
 3 }
 4 - (void)cacheBeginPointForTouches:(NSSet *)touches {
 5     if ([touches count] > 0) {
 6         for (UITouch *touch in touches) {
 7             CGPoint *point = (CGPoint *)CFDictionaryGetValue(touchBeginPoints,
 8 touch);
 9 } }
10     if (point == NULL) {
11         point = (CGPoint *)malloc(sizeof(CGPoint));
12         CFDictionarySetValue(touchBeginPoints, touch, point);
13 }
14     *point = [touch locationInView:view.superview];
15 }
复制代码

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值