Hiding button in annotation callout Swift - ios

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.)

Related

iOS PdfKit select and delete note annotation when long pressed/tapped

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.

ios mapview. Dismiss callout but keep annotation selected

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.

How to set draggable Map pin

I am developing an application in which I have included MapKit.
When first map is loaded at the time pin will be located at predefine place. And at that time drag-gable property of pin is set to NO.
Now I want to do this..
When user press button Edit it will allow user to drag pin. And when user drag pin and locate it at new place it will show user pin location name and lat long.
MKAnnotationView exposes the property draggable which can be set to enable dragging of each annotation added to map view.
The documentation for MKAnnotationView states:
If YES, the associated annotation object must also implement the setCoordinate: method. The default value of this property is NO.
Subclass MKAnnotationView and implement the setCoordinate method.
Then in your mapView:viewForAnnotation: method, set the draggable property to YES.

iOS Map: Deselect Annotation Only on Map Click

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?

How to create custom annotation and callout bubble in iphone?

I want to create a customized annotation and callout bubble on MKMapView. I need to use a customized view rather than default annotation pin and annotaion view(which is limited to show only title and a single line description). When user tap on an annotation, I would like to display more information on the callout bubble.
I passed by this control but I haven't used it:
http://cocoacontrols.com/platforms/ios/controls/custom-callout
I've found some pretty good controls at that site.

Resources