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



我正在UITableViewCell中嵌入一个MKMapView,它运行得很好。不幸的是,地图无法使用,例如缩放、滚动或点击。即使是来自苹果的法律链接也是无法点击的。

欢迎任何建议。

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)

我认为这是多手势识别器的问题。滚动视图(TableView(和MKMapView。

结账姿势识别器(_:应与同时识别(

最新更新