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 dir开发者_Python百科ection of where to look would be really helpful. thanks.
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);
}
精彩评论