gpt4 book ai didi

ios - UITableView 的 backgroundView 上的触摸事件

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:26 25 4
gpt4 key购买 nike

我有一个 UITableViewControllertableView 有一个 backgroundView View (更重要的是,它是一个 MKMapView), 设置为

self.tableView.backgroundView = _mapView;

当前背景 View 显示在屏幕上(我也有一个透明的表头来实现这一点)。我无法使 mapView(tableViewbackgroundView)响应用户交互。我的表头位于 map View 上方,是 UIView 的子类,具有以下覆盖:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
LogDebug(@"Clic en transparent view");
if (_transparent)
{
return nil;
}
return [super hitTest:point withEvent:event];
}

所以它应该通过事件;我不知道哪里出了问题,在其他类似问题中也没有找到任何解决方案。

必须将 mapView 保留为 tableView 的背景属性,因此请考虑到这一点。

有什么想法吗?

最佳答案

现在回答这个问题比较晚了。但是我在自己的项目中遇到了这个问题,经过一番研究我得到了答案。首先,我没有将后面的 View 分配给 tableView.backgroundView。相反,我使 tableView.backgroundColor 透明,然后将另一个 View 放在 TableView 下。

编辑:“在 table 下面”是指 tableViewanotherView 是同一父 View 的 subview ,并且 tableView.zPosition 大于 anotherView.zPosition.

然后我所做的就是覆盖 tableView:

(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

并让 tableView 避免保存不在其单元格中的事件。

代码如下:

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {

/// the height of the table itself.
float height = self.bounds.size.height + self.contentOffset.y;
/// the bounds of the table.
/// it's strange that the origin of the table view is actually the top-left of the table.
CGRect tableBounds = CGRectMake(0, 0, self.bounds.size.width, height);
return CGRectContainsPoint(tableBounds, point);

}

它对我来说就像一个魅力。希望它能帮助遇到此问题的任何其他人。

关于ios - UITableView 的 backgroundView 上的触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20444766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com