objective-c - 点击时返回标签的标签

标签 objective-c ios ios6 xcode4.5 uitapgesturerecognizer

我的 View 中有 5 个标签,分别标记为 1、2、3、4 和 5。我在它们上启用了用户交互,并添加了点击手势。

现在我想要的是获取被触摸标签的标签。

我正在做这样的事情:

tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureSelector)];

tapGesture.numberOfTapsRequired = 1.0;     

- (void)tapGestureSelector :(id)sender
{
    // I need the tag to perform different tasks.
    // So that I would like to get the touched label's tag here.    
}

如果我的问题不清楚,请问我。

感谢期待中的帮助。

最佳答案

首先,我添加了 oneLabeltwoLabel 作为 self.view 的 subview 。那我觉得就没有必要去获取tag了。

CGPoint tapPoint = [tapGesture locationInView:self.view];

if (CGRectContainsPoint(self.oneLabel.frame, tapPoint)) {
    NSLog(@"tapped one label");
} else if (CGRectContainsPoint(self.twoLabel.frame, tapPoint)) {
    NSLog(@"tapped two label");
}

关于objective-c - 点击时返回标签的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13304120/

相关文章:

ios - 将 GameKit key 添加到您的信息 plist 文件(错误)

ios - 按角度平移点 ios

ios - UIScrollView 是否仅适用于嵌入在导航控件中的 View Controller ?

ios - 为什么动画播放后 View 会消失?

ios - 使用自动布局动画化 UILabel 宽度

ios - 究竟什么代码必须放在 iOS 的主线程上?

ios - 自定义 UIButton(CheckBox) 添加响应者到 Action iOS SDK

objective-c - calloutAccessoryControlTabbed 委托(delegate)未被调用

ios - 如何在 TableView 自定义期间调用方法 "willDisplayFooterView"?

objective-c - 将 Objective C 自引用结构转换为 Swift