2013-04-06 137 views
-4

- (void)ccTouchesBegan ...对ios触摸代码感到困惑

UITouch * touch = [touches anyObject];

CGPoint location = [touch locationInView:[touch view]];

有人可以请详细解释这两行代码究竟发生了什么。 感谢

+0

你有没有花时间阅读文档,看看它是如何描述的? – 2013-04-06 19:43:29

+0

对不起,我意识到我应该问更多的细节,这就是为什么我问这个问题 – user2252901 2013-04-06 19:48:53

回答

1
UITouch *touch = [touches anyObject]; 

touchesUITouch一个NSSet。代码只需从touches中获取一个对象,并将其分配给名为touch的变量。这隐含地假定只包含一个元素。

CGPoint location = [touch locationInView:[touch view]]; 

上面的代码行获取触摸在截获触摸的视图的坐标系中的(x,y)坐标。 CGPoint只不过是一个带有两个浮点值的C结构,xy

因此,底线将获得视图中触摸的坐标。