Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

iphone - How to get finger coordinates

I can not find how I can get the coordinates of the mouse/finger on an iphone in Xcode.

I tried:

NSPoint mouseLoc;
mouseLoc = [NSEvent mouseLocation];

But this seems not to work for iphone? The API does not recognise it.

Does anyone know a way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is Apple's doc: UIResponder Class Reference. And in a UIView or UIViewController's subclass you can add this method:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touched = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touched.view];
    NSLog(@"x=%.2f y=%.2f", location.x, location.y);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...