Search code examples
swiftmapkitios10ios12mapkitannotation

How to stop MapView from automatic scroll?


I have a MKMapView and some MKAnnotation. I want to select one of the MKAnnotation whenever user click on an item of my UICollectionView. this is my code for selecting one of the MKAnnotation.

func showAnnotationForItemAt(index: Int){
    for item in map.annotations{
        if item.title == items[index]["title"].string{
            map.selectAnnotation(item, animated: true)
            break
        }
    }
}

it works perfectly on iOS 12. but in iOS 10.3, map scrolls automatically to the annotation whenever I call map.selectAnnotation(item, animated: true). How can I prevent map from auto scrolling after calling selectAnnotation. I want it to be like what it happens in iOS 12


Solution

  • Please do animation false:

    map.selectAnnotation(item, animated: false)