我正在寻找一些示例代码来跟踪一个CFDictionary的UITouches。不幸的是,苹果文档并没有一个完整的例子。
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);
}
}发布于 2012-09-25 03:21:55
在触摸的整个生命周期内,UITouch的指针不会改变。您可以从指针创建NSValue。
// NSMutableDictionary * touchLookup; set up somewhere else...
NSValue * key = [NSValue valueWithPointer:touch];
[touchLookup setObject:touch forKey:key];https://stackoverflow.com/questions/12570987
复制相似问题