2015-10-19 87 views

回答

0

您需要將點擊手勢識別器添加到您的自定義視圖中。

-(void)handleTapGesture:(UITapGestureRecognizer *)tapGestureRecognizer{ 

    NSLog(@"3 tapped"); 
    //add code to present another View Controller 

} 


-(void)buttonView{ 
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; 
tapGestureRecognizer.numberOfTapsRequired=3; 
[self.customButtonView addGestureRecognizer:tapGestureRecognizer]; 

    } 

斯威夫特:

func handleTapGesture(tapGestureRecognizer: UITapGestureRecognizer) { 
    NSLog("3 tapped") 
    //add code to present another View Controller 
} 



    func buttonView() { 
    var tapGestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTapGesture:") 
    tapGestureRecognizer.numberOfTapsRequired = 3 
    self.customButtonView.addGestureRecognizer(tapGestureRecognizer) 
} 

可以在viewDidAppear調用此方法。

+0

這不是Swift。 – Wez

+0

我的錯誤....我會更新我的回答 –

+0

@ Mr.T謝謝你的回答,如果代碼很快就會有幫助。我也希望這些水龍頭在一秒鐘內完成,所以我也需要某種計時器。 –

0

按鈕沒有設置爲響應多個水龍頭。你必須自己模擬。

正如其他人所說,您可以創建一個輕擊手勢識別器並將其附加到任何視圖。對於某些視圖,您需要將userInteractionEnabled標誌設置爲true,然後纔會響應。

如果你想要一個按鈕來處理雙擊,你需要有沒有安裝動作的按鈕,但附加了一個2點擊手勢識別器。

相關問題