2012-02-15 94 views
1

這是我的問題,當我使用UILongPressGestureRecognizer,它只在第二次工作...我按了3秒的按鈕,它不工作,但第二次,我推3秒按鈕它工作正常...有些想法?UILongPressGestureRecognizer只調用第二次

-(IBAction)seleccionar1:(id)sender{ 
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)]; 
longpressGesture.minimumPressDuration = 3; 
[longpressGesture setDelegate:self]; 
[sender addGestureRecognizer:longpressGesture];} 

-(IBAction)seleccionar2:(id)sender{ 
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)]; 
longpressGesture.minimumPressDuration = 3; 
[longpressGesture setDelegate:self]; 
[sender addGestureRecognizer:longpressGesture];} 

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{ 
if(gestureRecognizer.view==boton1) 
{ 
    [boton1 setTitle:@"Funciona 1" forState:UIControlStateNormal]; 
} 
if(gestureRecognizer.view==boton2) 
{ 
    [boton2 setTitle:@"Funciona 2" forState:UIControlStateNormal]; 
}} 

感謝所有的朋友。

問候

回答

2

,因爲在第一次的動作不是添加到按鈕添加它的用戶動作..手勢之前例如在viewDidLoad中添加這樣的按鈕。

相關問題