简体   繁体   English

我如何获得可可粉/目标C中的触摸的位置?

[英]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. 我是Objective-C和Cocoa的新手,因此无法在网上找到与此相关的任何内容,因此我不确定是否有办法做到这一点。 any ideas or direction 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: 在iPhone上,您可以创建UIView的子类并实现功能-(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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM