简体   繁体   中英

MapKit iOS Pins Grabbing Focus

I'm creating an application that takes advantage of iOS Mapkit framework and also some code to create a custom annotation on the map.

The pins i am adding are downloaded and added when the download is complete (pretty standard practice im sure).

I am also showing the user's current location which, on first load, is brought to focus.

HOWEVER i'm having an issue, i'm not sure what is causing it. When my map loads with the annotations everything is fine and works as expected. However with the map pins showing i get a weird problem, focus is given to the map pins and when i begin to zoom around on the map other pins are brought to focus.

This problem means if i want to zoom right out on the map i can to a certain point, however weirdly i'm jumped to one of the pins which may be in another continent.

I'm not sure whether it's possible to remove focus from pins (which is what i want) or whether anyone has had a similar problem and knows how to fix.

Sorry that this isn't much information to go on but i know not of where the error is.

EDIT WITH MORE INFO

It appears after a few hours trying to find the source it comes down to....

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views

... and when new annotations comes into view. I cannot find a way to stop the annotations grabbing zoom however.

Your problem is with userinteraction enabled for pins. Try to disabled user interaction of the pins in viewforAnnotation method

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

 if (annotation.isKind(of: AnnotationModal.self)) {
            let anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)

 anView.isDraggable = false
 anView.isEnabled = false
 anView.isUserInteractionEnabled = false

}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM