如何从点击位置获取 CGPoint? [英] How to get a CGPoint from a tapped location?

查看:30
本文介绍了如何从点击位置获取 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

这篇关于如何从点击位置获取 CGPoint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆