2016-12-13 26 views
0

當我點擊我的表格視圖時,它將觸發touchesBegantouchesShouldBegin。但是,我的視圖單元上也有一個UIPanGestureRecognizer,並且在平移單元時,點擊其他單元不會觸發touchesShouldBeginUITableView tapgesture行爲

我需要的原因touchesShouldBegin是因爲我想在單元格被平移時停止觸摸。有其他方法可以用來做到這一點嗎?我曾嘗試將allowsMultipleSelection設置爲falsetrue

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    print("This will always be printed") 
} 

override func touchesShouldBegin(_ touches: Set<UITouch>, with event: UIEvent?, in view: UIView) -> Bool { 
    print("This will only be printed when no cells are being panned") 

    return true 
} 

回答

0

嘗試將UITableViewdelaysContentTouches屬性設置爲true

您也可以嘗試添加一個UIGestureRecognizerDelegateUIPanGestureRecognizer並:

extension MyViewController: UIGestureRecognizerDelegate { 
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { 
    return true 
    } 
}