我如何在可可/ objective-c中获得触摸的位置?

Joe*_*Joe 4 iphone cocoa-touch objective-c uikit

我希望获得触摸的位置,最好对应于屏幕的像素.我是Objective-c和cocoa的新手,并且无法在网上找到关于此的任何内容,所以我不确定是否有办法做到这一点.任何想法或方向看哪里都会有所帮助.谢谢.

jol*_*coa 7

在iPhone上你创建了UIView的子类并实现了funktion - (void)touchesBegan:(NSSet*)触及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);
}
Run Code Online (Sandbox Code Playgroud)