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.
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.
I have an app with map and in it there are some pins with their annotations.
I don't understand how to show a particular pin's annotation without tapping on it.
Callouts are generally shown when the annotation is "selected". While this is generally achieved by a user tapping on the annotation view (i.e. the pin), you can also programmatically "select" the annotation:
mapView.selectAnnotation(annotation, animated: true)
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 know that I can use didTapAtCoordinate that will deselect the marker when I tap else where on the map.
But If there are multiple marker and I tap another one (Ex. MarkerA -> MarkerB), Is there any call back when the previous marker DidDeselect?.
I look around in GMSMapView the but can't find any thing I can use.
I want to change the marker color or image when it being selected and change it back when another marker select or the marker deselect.
Thank you.
The doco for selectedMarker says:
The marker that is selected. Setting this property selects a
particular marker, showing an info window on it. If this property is
non-nil, setting it to nil deselects the marker, hiding the info
window. This property is observable using KVO.
So, you could use Key Value Observing to be notified of changes to selectedMarker. If you use NSKeyValueObservingOptionOld when setting up KVO (described in more detail here), you will be notified of the old value, ie the marker which was deselected.
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?