ios - 使用 CFDictionary 跟踪 UITouches

标签 ios

<分区>

我正在寻找一些示例代码来使用 CFDictionary 跟踪 UITouches。不幸的是,apple-docs 没有完整的示例。

http://developer.apple.com/library/IOs/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html#//apple_ref/doc/uid/TP40009541-CH3-SW7

我目前正在使用 NSMutable 数组,但我想存储完整的 UITouch 对象,以便同时获取时间戳。

NSMutableArray *touchArray_val;


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    touchArray_val = [[NSMutableArray alloc] init];             
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 

     for(UITouch *t in touches){
         CGPoint currentPoint = [t locationInView:self];
         [touchArray_val addObject:[NSValue valueWithCGPoint: currentPoint]];    
     }

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{        
    NSLog(@"%i",[touchArray count]);

    for(NSValue *val in touchArray_val){        
        NSLog(@"%@",val);      
    }
}

最佳答案

UITouch 的指针在触摸的整个生命周期内都不会改变。您可以从指针创建一个 NSValue。

 // NSMutableDictionary * touchLookup; set up somewhere else...
 NSValue * key = [NSValue valueWithPointer:touch];
 [touchLookup setObject:touch forKey:key];

关于ios - 使用 CFDictionary 跟踪 UITouches,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12570987/

相关文章:

ios - 调用中参数 'totalBytesWritten' 缺少参数

ios - 将时间从字符串转换为日期仅在模拟器上崩溃

iphone - 带有关闭 block 的 presentViewController

ios - SpriteKit iPhone/iPad 不同的分辨率,需要相同的物理

ios - iPhone 4s-UIImage CGImage图像尺寸

ios - 在 View Controller 中获取已关闭 PopupDialog 的通知

ios - Xcode 5缺少代码签名权利?

ios - 如何从 iOS7 中的 UIWindow 对象中获取 UIAlertView

iphone - Objective-C 与 Microsoft Dynamics CRM 交互

ios - 将 subview 置于一切之上,但置于另一个 UIView 之下