Joe
Joe

Reputation: 1354

how do i get the location of a touch in cocoa/objective-c?

I am looking to get the location of a touch, preferably corresponding to the pixels of the screen. I'm new to objective-c and cocoa and haven't been able to find anything on the web about this so i'm not sure if there is even a way to do it. any ideas or direction of where to look would be really helpful. thanks.

Upvotes: 5

Views: 5947

Answers (1)

jollyCocoa
jollyCocoa

Reputation: 691

On iPhone you make a subclass of the UIView and implement the funktion -(void)touchesBegan:(NSSet *)touches withEvent:(NSEvent *)anEvent:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
   UITouch *myTouch = [[touches allObjects] objectAtIndex: 0];
   CGPoint currentPos = [myTouch locationInView: self];
   NSLog(@"Point in myView: (%f,%f)", currentPos.x, currentPos.y);
}

Upvotes: 8

Related Questions