I'd like to a-synchronically load images for my custom MKAnnotationView; I'm already using the EGOImageView-framework (it goes very well with UITableViews), but I fail to make it work on MKMapView. Images seem to be loaded, but I cannot refresh them on the map - [myMap setNeedsDisplay]
does nothing.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
This is the only way I've found to force redraw of MKAnnotationViews:
// force update of map view (otherwise annotation views won't redraw)
CLLocationCoordinate2D center = mapView.centerCoordinate;
mapView.centerCoordinate = center;
Seems useless, but it works.
(I don't see how to indicate that this post pertains to zerodiv's answer.) I was able to get zerodiv's method to work by adding a kickstart of sorts, forcing a meaningless but different coordinate, then restoring the prior, correct one. The screen doesn't flash at all because of the first location.
I haven't tried it myself, but it might work:
Get a view for annotation using MKMapView
- (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation
method and set new image to it.Edit: Tried to do that myself and this approach worked fine for me:
After calling this method all annotations images were updated.
This worked for me
I found only one reliable way to update annotation, others methods didn't work for me: just removing and adding annotation again:
This code will make -[mapView:viewForAnnotation:] to be called again and so your annotation view will be created again (or maybe reused if you use dequeueReusableAnnotationViewWithIdentifier) with correct data.
I wanted to refresh user location pin with new selected avatar. I found another fast solution for that case. I have 2 screens. The first one is for selecting avatar and the second is for displaying user on map.
swift 5 You can change user location image by creating MKAnnotationView
So if user will change avatar to something else, for example to "avatar2" it won't refresh.
In order to refresh user location image i added this code in viewWillAppear()