我想获取触摸的位置,最好是对应于屏幕上的像素。我刚接触objective-c和cocoa,没有在网上找到相关信息,所以不确定是否有方法可以实现。如果您有任何想法或者方向,请告诉我,谢谢。
我想获取触摸的位置,最好是对应于屏幕上的像素。我刚接触objective-c和cocoa,没有在网上找到相关信息,所以不确定是否有方法可以实现。如果您有任何想法或者方向,请告诉我,谢谢。
在 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);
}