![](/img/trans.png)
[英]Passing touch events to uiimageview within a scrollview added as subview to view
[英]Touch events of Scrollview in subview of UITableviewCell in iOS
我試過通過互聯網搜索這個問題,但無法提出解決我的問題的解決方案。
我做的一個子類UITableViewCell
中,我加入UIScrollView
作為一個子視圖,現在我想滾動手勢由scrolView被傾聽並單擊手勢被傾聽UItableView
。
使用這種布局也是對抗Apple的HIG
這是一個老問題,但由於我沒有找到一個好的答案,我想我會提供一個。 此方法捕獲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) } }
如果滾動視圖是表視圖的子視圖,則可以捕獲手勢並將其發送到其父視圖,如下所示:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.nextResponder touchesBegan:touches withEvent:event];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.