2014-10-20 56 views
2

UITapGestureRecognizer與UIPickerView不起作用。爲什麼?用於UIPIckerView的UITapGestureRecognizer

class someVC: UIViewController, UITapGestureRecognizerDelegate 

override func viewDidLoad() { 
    let tap = UITapGestureRecognizer(target: self, action: "dismissKeyboard") 
    self.pickerView.addGestureRecognizer(tap) 
    tap.delegate = self 
} 

func dismissKeyboard() { 
    textField.resignFirstResponder() 
} 

回答

8

我加入覆蓋getureRecognizer

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { 
    return true 
} 
0

看起來不錯,是否有另一個手勢識別器吞下水龍頭?您需要確保您的對象位於視圖堆棧的頂部以確保它被觸發。你還設置了委託,委託方法是否被調用?或者他們也不會開火嗎?如果他們不這樣做,那麼這意味着你的輕擊手勢沒有被觸摸(另一個手勢正在觸摸),如果它被觸發,這意味着該動作有問題(但我懷疑是這種情況)。

+0

謝謝解決的問題。我通過覆蓋gestureRecognizer解決了這個問題 – 2014-10-20 12:03:01