I have map with annotations and some buttons and views around it. I'm using didSelectAnnotationView and didDeelectAnnotationView but deselect appears to be called anytime anything on screen is clicked, including my buttons. Is there a way to only have deselect fired only when a click is on the map and not on a button or somewhere else?
Related
I am adding annotations to a pdf document and this works as expected. Now I also want to delete them and here I am facing some issues.
As I see, it should work out of the box, but when I long click on an annotation mostly of the time the text around of it is being selected but not the annotation itself.
This is one example where I created a big annotation so that I am sure that my finger is not touching any text around of it. When I long click on it this is what I get most of the time (this is not always, sometimes the menu also appears over the annotation and I am able to delete it via the delete action):
I also tried to add a long-press/tap gesture on the PDFKit and in these situations when I long click on the annotation and the text is being selected, my long press gesture is not being fired. I assume that the view hierarchy inside PDFKit is causing this issue.
With the tap gesture I am able to detect the annotation when it's being tapped, but in this case the controller?? that is displaying the annotation text is not being shown (I guess because I intercept the tap gesture). Is there a way to still trigger the annotation display and modify the controller (add additional navigation button since now there is just a "Done" button)? This is the particular controller when I tap the orange note icon:
Adding hightlight annotations to text and removing them works as expected (because there is no problem with selecting text)
Is there a way to somehow force the PDFKit to mark the annotation as selected when I long click on it? Modifying the controller that is being displayed when an annotation is being tapped would also help.
In case somebody else is struggling with this.
I chose to display the annotation inside a custom controller.
First I implemented a TapGestureRecognizer on the pdfview, from there got the annotation and then displayed the annotation inside the custom controller.
Im my MKMapView, I have a callout of an MKAnnotationView that works fine most of the time and looks like this:
The icons in the callout are buttons.
The problem:
In this case, hidden by the callout, there is an annotation on the map, exactly behind of a button.
When I tap on this button, the AnnotationView behind the button gets the touch event.
When I tap on a button without an annotation behind, the button gets the touch event.
I found this out using the accepted answer of How to debug who is eating my touches in UIKit?
How can I make sure that a touch on a button in the callout doesn't get eaten by an MKAnnotationView that is rendered behind the callout?
There is very much code and at the moment I have no idea which code is relevant to show to you.
Found a solution (I did not find a solution using hitTest):
I now use my own UIView as callout (see Robs comment below the question as a start). That does not change my problem described in the question.
I noticed that I don't have the describd problem when I hit on the buttons in my callout view.
So I put an invisible custom button over all my non interactive labels and textViews. The infoButton shown below does nothing but catching taps. It has the same size as infoStackView below:
This solution should also work if annotationView.detailCalloutAccessoryView is used, as I did when I posed the question.
I am wondering how I can hide and show a button in an annotation callout?
I set up my annotation view to have a left and a right button, each doing a separate task. The user can add an annotation by selecting a location from a table or long press.
I want the left button to be accessible and the right button to be hidden when the annotation is added via selection from table and the left button to be hidden the the right button to be accessible when the annotation is added via long press.
I have the buttons in the callout working but I can't figure how how to hide/show them. Any help is much appreciated!
Don't use a generic MapAnnotation object. Create a custom object that conforms to the MKAnnotation protocol and give it an Enum property that has a different value if it's added from your table or from a long press.
In your viewForAnnotation method, cast the annotation object to your custom type and check the property before deciding which callouts to add. (You'll need special-case code for the user location, as always.)
I've got a situation where I have some custom annotations on mapview. When these annotations are selected I change the image to a selected state via the
didSelectAnnotationView
method with a call to [view setImage] and I also show a callout bubble. The callout has an accessory view that adds a new subview with more information in it when tapped. All this works fine, except that when I tap the callout accessory view I want the callout to disappear, but the selected image state to remain. Currently the only way I know how to dismiss the callout is via
didDeselectAnnotationView
however this is also where I would set the image state to be the default unselected image.
Does anyone know if it is possible to dismiss the callout only but retain the selected state on my annotation?
I've sort of got this working by setting a boolean when the detailView has been added to decide whether or not to remove the "active" image. However it becomes tricky when I select a new annotation as I end up with multiple annotations showing the selected state image. I've tried looping through all annotations and setting their image to the "off" state but this doesn't seem to work and I've tried setting a reference to the currently selected annotation and changing the image on that, but again it hasn't worked.
Example flow:
User selects a pin
didSelectAnnotationView is called
Pin image changes to "active" and callout is shown
User taps accessory view in callout.
BOOLEAN popOverShowing is set to YES
didDeselectAnnotationView is called. As popOverShowing is YES the image is not changed to off state but callout disappears
User taps New annotation
Popover disappears and popOverShowing set to NO
New annotation is set to "active" image
all other annotations should get reset to off image (this is what doesn't seem to happen)
Keep the reference of previousPin set it off in didSelectAnnotationView unless is nil.
Then set the new selected pin as previousPin. Hope it helps.
I need help regarding removing annotation by double click.
Once I click on any existing annotation on my map, how do I differentiate which annotation/pin selected (double click)?
or any other suggested/common way to delete pins from mapView?
thanks in advance!!
double tap gesture recognizer is reserved by map kit framework to zooming in map view by default, but you can suppress that by using "hittest" in custom "MKPinAnnotationView" class.
I prepeared an example to show how to make callout touchable in map view with "hittest".
you can achieve this problem with the same way as I can do for callouts.
Detect tap on title of callout