首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用CFDictionary跟踪UITouches

使用CFDictionary跟踪UITouches
EN

Stack Overflow用户
提问于 2012-09-25 02:45:39
回答 1查看 438关注 0票数 1

我正在寻找一些示例代码来跟踪一个CFDictionary的UITouches。不幸的是,苹果文档并没有一个完整的例子。

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

我目前使用的是NSMutable数组,但我想存储完整的UITouch对象,因此也要获得时间戳。

代码语言:javascript
复制
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);      
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-25 03:21:55

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

代码语言:javascript
复制
 // NSMutableDictionary * touchLookup; set up somewhere else...
 NSValue * key = [NSValue valueWithPointer:touch];
 [touchLookup setObject:touch forKey:key];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12570987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档