How to get a CGPoint from a tapped location?

后端 未结 6 1577
青春惊慌失措
青春惊慌失措 2020-12-01 06:32

I\'m working on a graphing calculator app for the iPad, and I wanted to add a feature where a user can tap an area in the graph view to make a text box pop up displaying the

6条回答
  •  [愿得一人]
    2020-12-01 07:03

    Try This

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    {
      UITouch *touch = [touches anyObject];
    
      // Get the specific point that was touched
      CGPoint point = [touch locationInView:self.view]; 
      NSLog(@"X location: %f", point.x);
      NSLog(@"Y Location: %f",point.y);
    
    }
    

    You can use "touchesEnded" if you'd rather see where the user lifted their finger off the screen instead of where they touched down.

提交回复
热议问题