【问题标题】:is there any way to get a cgpoint from a tapped location without having to used a touch method such as touches began or touches moved?有什么方法可以从点击位置获取 cgpoint,而不必使用触摸方法,例如触摸开始或触摸移动?
【发布时间】:2014-07-04 00:47:19
【问题描述】:

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

【问题讨论】:

标签: ios objective-c


【解决方案1】:

您可以使用 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 ;)
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多