Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a CGPoint from a tapped location?

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 coordinate of the point they touched. How can I get a CGPoint from this?

like image 482
jkolber Avatar asked May 11 '12 17:05

jkolber


1 Answers

you have two way ...

1.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  {   UITouch *touch = [[event allTouches] anyObject];   CGPoint location = [touch locationInView:touch.view]; } 

here,you can get location with point from current view...

2.

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]; [tapRecognizer setNumberOfTapsRequired:1]; [tapRecognizer setDelegate:self]; [self.view addGestureRecognizer:tapRecognizer]; 

here,this code use when you want to do somthing with your perticular object or subview of your mainview

like image 147
Paras Joshi Avatar answered Nov 01 '22 22:11

Paras Joshi