It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
我正在寻找一些示例代码来使用CFDictionary跟踪UITouch。不幸的是,苹果文档没有完整的示例。

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];

10-07 14:13