开发者

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

开发者 https://www.devze.com 2023-01-09 03:42 出处:网络
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\

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号