我已經嘗試通過互聯網搜索有關此問題,但無法拿出解決方案來解決我的問題。在iOS中的UITableviewCell的子視圖中觸摸滾動視圖的事件
我必須做的UITableViewCell
一個子類中,我加入UIScrollView
作爲一個子視圖,現在我想滾動手勢由scrolView被傾聽並單擊手勢由UItableView
聽着。
也是用這個佈局是針對蘋果的HIG
我已經嘗試通過互聯網搜索有關此問題,但無法拿出解決方案來解決我的問題。在iOS中的UITableviewCell的子視圖中觸摸滾動視圖的事件
我必須做的UITableViewCell
一個子類中,我加入UIScrollView
作爲一個子視圖,現在我想滾動手勢由scrolView被傾聽並單擊手勢由UItableView
聽着。
也是用這個佈局是針對蘋果的HIG
如果滾動視圖爲表視圖的一個子視圖,可以捕捉手勢,並將其發送到它的父視圖這樣的:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.nextResponder touchesBegan:touches withEvent:event];
}
這是一個老問題,但由於我沒有真正找到一個好的答案,我想我會提供一個。這種方法捕獲UIScrollView(包含在表格單元內)和tap事件直接在UITableView單元上的tap事件,並將它們傳遞給UITableViewDelegate。它也允許你滾動你的UIScrollView內容而不需要傳遞滾動事件。不需要任何子類。
// Capture taps on scrollView fields and pass along to tableView let tap = UITapGestureRecognizer(target: self, action: "tapIntercept:") tableView.addGestureRecognizer(tap)
// Get the location of the table cell beneath the scrollView and pass the event off to the tableView func tapIntercept(recognizer: UIGestureRecognizer) { let point = recognizer.locationInView(tableView) if let indexPath = tableView.indexPathForRowAtPoint(point) { tableView(tableView, didSelectRowAtIndexPath: indexPath) } }
參見[UIScrollView的內部的UITableViewCell觸摸檢測](http://stackoverflow.com/questions/6636844/uiscrollview-inside-uitableviewcell-touch-detect)鏈路它顯示觸摸檢測 –
最好是可以添加單敲擊手勢到viewDidLoad中的tableview。 –