我有2個uibutton和1個標籤,並且longpressgesture與這些控件有界。當longpress發生在任何控件上時,如何獲得longpress發生在下面的對象是我寫的代碼。UILongPressGestureRecognizer與uibutton和uilabel問題
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>)>>
從中我怎樣才能對象上whcih的refrence longpress事件發生 我的意思是我如何知道我是否preessed UiLabel或Uibutton?
u mean mean sender.view? – KsK 2012-08-15 18:39:00
如果它然後發件人沒有視圖屬性我已經檢查過它 – KsK 2012-08-15 18:39:46
什麼是發件人的類?如果它是UILongPressGestureRecognizer,它應該有一個視圖屬性,因爲它是UIGestureRecognizer的子類。 – J2theC 2012-08-15 18:42:26