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

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...