2011-08-10 35 views
0

我必須繼續這樣的類iphone,應用程序認爲我按住按鈕2次

@interface UIGestureHolder : UILongPressGestureRecognizer { 

    int tag; 
} 
@property (nonatomic, readwrite) int tag; 

@end 



@implementation UIGestureHolder 
@synthesize tag; 
@end 

然後我給你這一個按鈕,這樣,當它舉行buttonheld功能呼籲:

UIGestureHolder *longpressGesture = [[UIGestureHolder alloc] initWithTarget:self action:@selector(buttonHeld:)]; 
     longpressGesture.minimumPressDuration = 1.5; 

     [longpressGesture setDelegate:self]; 
     longpressGesture.tag=i; 
     [contactButton addGestureRecognizer:longpressGesture]; 
     [longpressGesture release]; 

按鈕功能:

-(void)buttonHeld:(id)sender 
{ 


    int i = ((UIControl *) sender).tag; 

    ...... 

} 

當我按住按鈕1.5秒或任何我想要的時間,運行時告訴我我按了按鈕t爲什麼每次1.5倍?它以後會導致例外。

爲什麼運行時認爲我按住按鈕兩次?

回答

0

手勢識別器通知你,當他們的狀態改變。將代碼更改爲:

-(void)buttonHeld:(UILongPressGestureRecognizer*)longPressRecognizer 
{ 
    if(longPressRecognizer.state == UIGestureRecognizerStateBegan) 
    { 
     int i = ((UIControl *) sender).tag; 
     ...... 
    } 
} 
0

也許該按鈕也啓用了單擊功能?按鈕的行爲是點擊一次&事情發生了,對吧?

responder指定給您的按鈕時,您做了什麼?嘗試禁用該&看看你是否得到相同的...

相關問題