如何从tapped位置获取CGPoint? [英] How to get a CGPoint from a tapped location?
本文介绍了如何从tapped位置获取CGPoint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为iPad制作一个图形计算器应用程序,我想添加一个功能,用户可以在图表视图中点击一个区域,弹出一个文本框,显示他们触摸的点的坐标。我如何从中获得CGPoint?
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?
推荐答案
你有两种方式......
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
这篇关于如何从tapped位置获取CGPoint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文