ios - 有什么方法可以从点击位置获取 cgpoint 而不必使用触摸方法,例如触摸开始或触摸移动?

标签 ios objective-c

有没有什么方法可以从点击的位置获取 cgpoint 而不必使用触摸方法,例如触摸开始或触摸移动?我问是因为我有一个内部带有 UITableView 的 View ,并且由于某种原因触摸方法似乎无法在 TableView 内部工作。

最佳答案

您可以使用 UITapGestureRecognizer

你应该把它放在一个初始化方法中:

UITapGestureRecognizer * = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];
[theTargetView addGestureRecognizer:tapRecognizer];//theTargetView could also be self.view

目标类中的其他地方:

- (void)tapRecognized:(UITapGestureRecognizer *)recognizer
{
    if(recognizer.state == UIGestureRecognizerStateRecognized)
    {
        CGPoint point = [recognizer locationInView:recognizer.view];
        //your coordinates ;)
    }
}

关于ios - 有什么方法可以从点击位置获取 cgpoint 而不必使用触摸方法,例如触摸开始或触摸移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24557688/

相关文章:

ios - 在 Realm 中存储来自 API 的数据

ios - 搜索字典数组的简便方法

javascript - 在 Cocoa/OSX 应用程序中打包 node.js

ios - 如何以编程方式检查 iPhone 中可用的 3D Touch?

ios - 这个观点叫什么?操作系统

ios - navigationItem 的标题字体是什么?

ios - CAL层 : Screen point to Layer point

objective-c - 使用 NSURLSession 时 UI 被阻塞

iphone - 使用自动布局导致按钮停止工作

ios - UITableViewCells 未扩展以适合文本