1
我正在尋找一些示例代碼來跟蹤CFDictionary的UITouches。不幸的是,蘋果文檔沒有一個完整的例子。使用CFDictionary跟蹤UITouches
我目前使用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);
}
}
從文檔:「你應該使用CFDictionaryRef類型,而不是一個NSDictionary對象;後者複製其鍵,但UITouch類不採用NSCopying協議,這是需要的對象拷貝。」 – RParadox