【发布时间】:2012-08-15 18:33:56
【问题描述】:
我有 2 个 uibutton 和 1 个标签,并且 longpressgesture 绑定到这些控件。当在任何控件上发生长按时,如何获取下面发生长按的对象是我编写的代码。
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[btn addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
//[self.view addSubview:btn];
btn.userInteractionEnabled = YES;
// add it
[self.view addSubview:btn];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
[btn addGestureRecognizer:longPress];
下面是长按调用的函数
-(void)handleLongPress:(id)sender{
}
如果我打印发件人的描述然后我得到
<UILongPressGestureRecognizer: 0x6aa4480; state = Began; view = <UIRoundedRectButton 0x6aa9570>; target= <(action=handleLongPress:, target=<ViewController 0x6a8cc60>)>>
从中我怎样才能在发生 longpress 事件时获得对象的引用 我的意思是我怎么知道我按下的是 UiLabel 还是 Uibutton?
【问题讨论】:
标签: iphone ios uibutton gesture