我正在为 iPad 开发一个图形计算器应用程序,我想添加一个功能,用户可以在该功能中点击图形 View 中的一个区域,弹出一个文本框,显示他们触摸的点的坐标。我怎样才能从中获得 CGPoint?
最佳答案
你有两种方式......
1.
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
}
在这里,您可以从当前 View 获取点的位置...
2.
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[self.view addGestureRecognizer:tapRecognizer];
这里,当你想对你的特定对象或你的主视图的 subview 做一些事情时使用这段代码
关于ios - 如何从点击的位置获取 CGPoint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10556120/