Swift 5 中的用户无法访问 UITableViewCell 中的 MKMapView

MKMapView in UITableViewCell is not reachable for user in Swift 5

我在 UITableViewCell 中嵌入了一个 MKMapView,效果很好。不幸的是,该地图无法使用,例如缩放、滚动或点击。即使是 Apple 的合法 link 也不可点击。

欢迎任何建议。

let cell = UITableViewCell(style: .default, reuseIdentifier: "locationDetailMapCell")
            
let mapView = MKMapView()
            
mapView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: 400)
mapView.mapType = .standard
mapView.showsUserLocation = true
mapView.isZoomEnabled = true
mapView.isScrollEnabled = true

mapView.setRegion(MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: CLLocationDegrees(currentLocation.latitude), longitude: CLLocationDegrees(currentLocation.longitude)), span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)), animated: true)
            
let pin = MKPointAnnotation()
pin.coordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(currentLocation.latitude), longitude: CLLocationDegrees(currentLocation.longitude))
mapView.addAnnotation(pin)
            
cell.addSubview(mapView)
            
return cell

您应该将 mapView 添加到单元格的 contentView 而不是直接作为单元格的子视图。

cell.contentView.addSubview(mapView)

我认为这是多个 gesture-recogniser 的问题。 Scrollview(TableView)和MKMapView。

结帐gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)