iOS 11 MKAnnotationView prepareForReuse dismiss the pin view in Map view - ios

what I want to do is when I deselect an pin, the pin view change it's UI back to unselected state(e.g change color of background of the pin)
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
//do something;
XLMapItemAnnotation* mapItem = [self annotationForView:view];
[view prepareForReuse];
}
by having this code, when I run the app in iOS 11, if I deselect a pin, the pin disappear in the map view totally. and if I remove the prepareForReuse, everything would be fine.
and the some code if I run the app in iOS 10, everything is fine, no pin get disappeared.
can sbd give me a hint, what could be wrong?

You should not call -prepareForReuse yourself, it's intended for MapKit to call itself.

As #Tim Johnsen said, -prepareForReuse is intended for MKAnnotationView's reuse mechanism, you should not call it yourself.
In iOS 11, MapKit introduce clustering algorithm for MKAnnotationView(But after some try, I found it cause strange behavior sometimes). In this case, MKAnnotationView.isHidden is set as true by default. So after you invoking -prepareForReuse, MKAnnotationView is hidden.
If you want to change color of the pin, just change pinTintColor property directly, or use a function to reset all properties as needed.

Related

Mapkit Callout Accessory Button Activation

I am using MapKit to display a map with many annotations. Each of these annotations has a callout with a UIButton. Most everything works properly, but any time there is an annotation behind the UIButton, it becomes impossible to activate it. I want the UIButton to be activatable regardless of background annotations. Is there a way to ignore the annotations directly behind the callout?
I have found an appropriate workaround to this issue:
(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
[view.superview bringSubviewToFront:view];
}
https://github.com/danielbarela/ios-map-callout-test/issues/1

checking if callout view is pressed (mapBox iOS SDK)

i'm wondering what is the best way to check - is callout view pressed using mapBox iOS SDK?
The only method that i find is this one
- (void)tapOnCalloutAccessoryControl:(UIControl *)control forAnnotation:(RMAnnotation *)annotation onMap:(RMMapView *)map
but this method checking is accessory pressed in callout view.
Any ideas how to achieve this? Thanks
There is a delegate method called tapOnLabelForAnnotation:onMap in RMMapViewDelegate, you can use this method to get informed about the user tapping the annotation label.
Delegate methods for detecting a press of the callout, instead of just its accessories, do not exist currently.

MKMapKit disalow deselection of callout bubble

I would like to know how I can make sure that a callout bubble can't get deselected on a MKMapView.
Whenever I press on the map (background), this view:
Turns to:
Which I do not want to allow. Yet I do want to keep the callOutButton support.
You could just programmatically select your annotation whenever annotations get deselected (using the corresponding delegate method). If you don't animate this selection then it looks as if the annotation never got deselected in the first place.
Example:
// MKMapView Delegate
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
// Replace "myAnnotation" with whichever annotation you need to remain selected
[mapView selectAnnotation:self.myAnnotation animated:NO];
}
I tried this in a test project and it works fine (it doesn't flicker or anything). It's not exactly disabling deselection but the resulting effect is the same, so it might be a good workaround.

mkmapview custom callout bubble ios6

I'm encountering a mystery issue when selecting a pin in the mapview iOS6
BTW, it works correctly in iOS 5, i'm not sure what they changed in the map of iOS 6 that produce this issue.
NOTE that when I click on the map, the callout directly go over the pins and shows correctly
any help/clue would be appreciated,
Thanks in advance
the answer might vary a bit depending on how you're implementing your custom callout bubble. This was/is the solution I'm using: Customize the MKAnnotationView callout and I ran into the exact same problem.
Basically, everytime the callout is going to show, I had to bring the subview to the front.
In this case, my custom callout bubble is a class called 'BaseCalloutView' which contains a UIView as its ContentView property (as you can see in the UML diagram at the link above). When the annotation is selected, it triggers the 'animateIn' function of the BaseCalloutView, into which I added:
[self.superview bringSubviewToFront:self];
As I mentioned, your mileage may vary depending on how you're implementing the custom callout bubble. I can provide you with the full code if needed - but to be honest 90% of my code is from the link above.
This solution didn't work for me, however the one did:
Custom Annotation View do not work on iOS6
Sorry not sure how to link answers properly.
In IOS 5 and IOS 6 , I try this and it's ok
the pin never overlap CalloutView.
I use custom calloutview , in file Base calloutView I add this :
- (void)didMoveToSuperview {
[super didMoveToSuperview];
[self.superview bringSubviewToFront:self];
}
I am using same code base, got same problem. [self.superview bringSubviewToFront:self]; doesn't work for me, not matter where did I put it. [annimateIn] or [didMoveToSuperView] or [layoutIfNeeded]
Because this problem went away by finger moving the map a little bit, so I found it is very easy to simulate this effect by put code in - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view. The offset is very small, no visual movement can be noticed at all.
CLLocationCoordinate2D newCenterCoordinate = {self.mapView.region.center.latitude + 0.0000001,
self.mapView.region.center.longitude + 0.0000001};
[self.mapView setCenterCoordinate:newCenterCoordinate animated:NO];

Map callout expansion animation like the one in Maps when the disclosure button is pressed

When selecting the disclosure button on a callout, the callout animates to the slide over and expand into larger area with more information.
Besides making this component from scratch, does anyone know how to make annotation callouts do this?
According to this: http://www.cocoacontrols.com/controls/gikanimatedcallout
, Apple is using a private API. The link above has code that tries to replicate what Apple does.
you should use below delegate method
(void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
then in this delegate method, you should create an disclosure button.
if(buttonType==disclosurebutton) then show custom UIView.
I think that will help overall.

Resources