2013-06-19 42 views
1

我正在使用應用程序,我需要調用單擊手勢方法而無需觸摸或輕掃任何東西。我想在initWithframe方法調用時調用該方法。我只想以編程方式調用此方法一次。請幫助我。我該怎麼做?感謝你。以編程方式調用手勢方法

+0

直接調用方法..如果是不可能在這個時候你可以調用延遲performSelector:@selector(invoke)withObject:nil afterDelay:1。 – lukaswelte

+0

只需創建一個方法,即可完成您想要的操作並調用它。如果您沒有使用特定於實際識別器的任何內容,只需調用其識別器參數爲零的處理程序方法即可。 – Abizern

+0

@lukaswelte在主線程上執行'dispatch_async'是比較常見的做法,而不是延遲調用performSelector。 – Abizern

回答

2

試試這個

UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; 
    recognizer.delegate = self; 
    [view addGestureRecognizer:recognizer]; 

和方法

- (void)handleTap:(UITapGestureRecognizer *)recognizer {  
} 

要programatically.Why你需要操縱tap.Just調用做到這一點的方法directly.To調用方法使用

[self handleTap:nil]; 
+1

閱讀問題。他問的是如何直接調用方法,而不是如何使用處理程序設置識別器。 – Abizern

+0

@Abizern更新了答案 –

0
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] init]; 
    gesture.direction = UISwipeGestureRecognizerDirectionLeft; 
    [self handleSwipe:gesture]; 
相關問題