user2252901
user2252901

Reputation: 21

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

Can someone please explain what's exactly going on with this line of code starting at CGPoint. This comes from the -(void)ccTouchesBegan...

UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];

In particular I'm not understanding the [touch view] part.

Thanks

Upvotes: 2

Views: 1137

Answers (2)

Sulthan
Sulthan

Reputation: 130102

[UITouch view] documentation

The value of the property is the view object in which the touch originally occurred. This object might not be the view the touch is currently in.

In other words, it's the innermost view at the touched position. However, if you tap and move the finger, the view doesn't change even if the touch is already in a different view.

Upvotes: 1

matt
matt

Reputation: 535121

In particular I'm not understanding the [touch view] part.

[touch view] is the UIView that user actually touched.

You might be helped further by reading my book's chapter on touches (at least the first few pages):

http://www.apeth.com/iOSBook/ch18.html

Upvotes: 1

Related Questions