Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 禁用MapKit Swift中的Mylocation标记点击_Ios_Swift_Swift3_Mapkit_Mkannotation - Fatal编程技术网

Ios 禁用MapKit Swift中的Mylocation标记点击

Ios 禁用MapKit Swift中的Mylocation标记点击,ios,swift,swift3,mapkit,mkannotation,Ios,Swift,Swift3,Mapkit,Mkannotation,我正在Apple map中添加MKAnnotationView,并在annotationView中创建一个点击事件。但是我的位置标记正在与annotationView点击交互。如何克服此问题。希望您理解我的问题。提前感谢 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { var annotationView = MKAnnotationView(

我正在Apple map中添加MKAnnotationView,并在annotationView中创建一个点击事件。但是我的位置标记正在与annotationView点击交互。如何克服此问题。希望您理解我的问题。提前感谢

 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    var annotationView = MKAnnotationView()

    guard let annotation = annotation as? ClientLocation
        else{
            return nil
    }
    if let dequedView = mapView.dequeueReusableAnnotationView(withIdentifier: annotation.identifier){
        annotationView = dequedView
    }
    else{
        annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotation.identifier)
    }
    ////////////////////////
    ///////////////////
    annotationView.rightCalloutAccessoryView = button
    annotationView.canShowCallout = true
    return annotationView
}

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
}

您可以从
MKMapViewDelegate
使用委托方法
viewforannotation
自定义注释视图

编辑:

我只是想复制你的代码,让我怀疑的只是你的类
ClientLocation
。如果您的
警卫让
返回nil,您必须检查此语句

您需要做的是检查视图类的类型是否来自您的委托,如下所示:

if annotation.isKind(of: MKUserLocation.self) {
    // this means we are handling the blue point or the user location.
    //then you can set the parameters for this view like
    annotationView.canShowCallout = false

    // or even unable user to interact with
    annotationView.isUserInteractionEnabled = false
}
您的代表应该是:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
    var annotationView = MKAnnotationView()
    guard let annotation = annotation as? ClientLocation
        else{
            return nil
    }
    if let dequedView = mapView.dequeueReusableAnnotationView(withIdentifier: annotation.identifier){
        annotationView = dequedView
    }
    else{
        annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotation.identifier)
    }

    if annotation.isKind(of: MKUserLocation.self) {
        annotationView.isUserInteractionEnabled = false
    }
    ////////////////////////
    ///////////////////
    annotationView.rightCalloutAccessoryView = button
    annotationView.canShowCallout = true
    return annotationView
}

您可以使用
MKMapViewDelegate
中的委托方法
viewforannotation
自定义注释视图

编辑:

我只是想复制你的代码,让我怀疑的只是你的类
ClientLocation
。如果您的
警卫让
返回nil,您必须检查此语句

您需要做的是检查视图类的类型是否来自您的委托,如下所示:

if annotation.isKind(of: MKUserLocation.self) {
    // this means we are handling the blue point or the user location.
    //then you can set the parameters for this view like
    annotationView.canShowCallout = false

    // or even unable user to interact with
    annotationView.isUserInteractionEnabled = false
}
您的代表应该是:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
    var annotationView = MKAnnotationView()
    guard let annotation = annotation as? ClientLocation
        else{
            return nil
    }
    if let dequedView = mapView.dequeueReusableAnnotationView(withIdentifier: annotation.identifier){
        annotationView = dequedView
    }
    else{
        annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotation.identifier)
    }

    if annotation.isKind(of: MKUserLocation.self) {
        annotationView.isUserInteractionEnabled = false
    }
    ////////////////////////
    ///////////////////
    annotationView.rightCalloutAccessoryView = button
    annotationView.canShowCallout = true
    return annotationView
}
你的代表

 public func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
        let userView = mapView.view(for: mapView.userLocation)
        userView?.isUserInteractionEnabled = false
        userView?.isEnabled = false
        userView?.canShowCallout = false
}
你的代表

 public func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
        let userView = mapView.view(for: mapView.userLocation)
        userView?.isUserInteractionEnabled = false
        userView?.isEnabled = false
        userView?.canShowCallout = false
}

这对我有用。试试这个

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.userLocation.title = nil
}

这对我有用。试试这个

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.userLocation.title = nil
}

谢谢。请用我的代码检查我编辑的问题。我不明白。你的目标是什么?不显示用户位置呼叫或根本不与用户位置交互?感谢您的回答。请给我一些时间。我将检查并接受。谢谢。请检查我编辑的问题,我的代码未收到。你的目标是什么?不显示用户位置呼叫或根本不与用户位置交互?谢谢您的回答。给我一些时间。我会检查并接受。