一般,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 }