MKMapKit disalow deselection of callout bubble - ios

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.

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

iOS 11 MKAnnotationView prepareForReuse dismiss the pin view in Map view

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.

mapView: didSelectAnnotationView: not functioning properly.

I'm building an IOS app that uses the built in map view. Im successfully placing custom annotations, etc. However, I'm having a problem with the delegate function that is called when an annotation is pressed (mapView:didSelectAnnotationView).
The first time I press an annotation, the function is called properly. However, if I proceed to click the same annotation again, the function does not fire. If I click on a different annotation at this point, the function WILL fire but then if I click on THAT annotation again, the function does not fire. Basically, I can never click on the same annotation twice in a row. The delegate function will only be called the first time. Has anyone encountered this problem? Is there somewhere in particular I should look for the bug?
Well, when you think about it, you have already selected that annotation view. It doesn't make sense for the delegate to tell you that the pin is selected if it already is.
A simple fix could be to set the annotation to deselected in the delegate call. This should allow you to get the call again.
[annotation setSelected:NO animated:NO];
Vists here for the method you need to call.
https://developer.apple.com/library/ios/documentation/mapkit/reference/MKAnnotationView_Class/index.html#//apple_ref/occ/instm/MKAnnotationView/setSelected:animated:
Friend suggested an idea and it turned out to be correct. When didSelectAnnotationView fires, it actually tags the annotation as selected somehow. Then when you click it again, the delegate function doesn't fire because it is 'already selected'. You have to manually deselect the annotation by calling the following function once you're done doing what you want.
[mapView deselectAnnotation:view.annotation animated:false];
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView
{
indexPathTag=aView.tag;
[mapView deselectAnnotation:aView.annotation animated:YES];
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)aView
{
}
I hope this will work for you :)
I have faced the same problem, this code worked for me.

MKPinAnnotationView disable selection/highlight but not lift and drag

I have a MKPinAnnotationView that I would like to be able to long press and drag around but not tap and select. Sometimes the user will touch just the right way (a short touch on the pin) and the pin will become highlighted (darkens) instead of lifting and dragging. I use the drag to show a magnifying glass so its a bit disruptive when the user touches a pin and drags but nothing happens.
Is there a flag of some kind I can set that prevents the pin from being tap selected and always goes to drag?
I've tried setting the following flags:
annotationView.selected = YES;
annotationView.canShowCallout = NO;
annotationView.highlighted = NO;
Which doesn't prevent the selection. I also tried flipping .selected to NO. I suppose I could override -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view but I'm not sure what I could put in there to bypass the selection. And there is no -(BOOL)shouldSelectAnnotationView... function.
You will most likely have to subclass the pin. Here is the best example I could find. I can not write one as I am not at my computer.
https://github.com/j4n0/callout
Good luck.

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