How to determine whether a MKPinAnnotationView CallOut is shown or not? - ios

I know how to make an MKPinAnnotation show and hide the annotation CallOut window.
But is there a property which I could query that would return a boolean as to whether the annotation CallOut window is currently visible or not?

Related

In iOS UI Testing, how do I identify the MKUserLocation annotation?

I'm struggling to identify how I can tell that the MKMapView is showing the current user location pin in a UI Test. This is a MKUserLocation annotation (and I've created an MKAnnotationView to use an image for the pin instead of the blue spot.)
Debugging tells me that the MKUserLocation annotation instance has a title of "My Location". I was expecting that the following would work:
app.maps.element.otherElements["My Location"]
would return it but [that code].exists returns false. Printing debugDescription of otherElements lists a whole set of annotations on the map but not the User Location.
Is there a different type of XCUIElement that represents the pin/annotation/annotation view that I can check for?
Use accessibility labels to access your MKAnnotationView. In your code, retrieve your user location annotation and set an accessibility label for it:
yourAnnotation.accessibilityLabel = "labelYouWillUseToFindIt"
Then during your tests you can do:
app.maps.element.otherElements["labelYouWillUseToFindIt"]
Use print(app.debugDescription) to see if your annotation is visible and if not, force it to be accessible with:
yourAnnotation.isAccessibilityElement = true
You can read more about accessibility labels here

How to show callout for pin on map without tapping on it?

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)

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.

Annotations, Annotations, Annotations

So `MKAnnotation's. Fun stuff.
My questions:
What's the difference between an annotation's title and its subtitle and how does that affect the visual component of the annotation?
What's the difference between a MKPinAnnotationView and a MKAnnotationView?
Are there different types of map annotations in iOS apart from pins?
Title is main heading of your pin.
The subtitle is actually displaying the address/(common info) of the dropped pin.You can store other deeply information of related to title that is puted on pin.
MKAnnotation is a protocol you need to adopt if you wish to show your object on a MKMapView. The coordinate property tells MKMapView where to place it. title and subtitle properties are optional but if you wish to show a callout view you are expected to implement title at a minimum.
MKAnnotationView visually presents the MKAnnotation on the MKMapView. The image property can be set to determine what to show for the annotation. However you can subclass it and implement drawRect: yourself.
MKPinAnnotationView is a subclass of MKAnnotationView that uses a Pin graphic as the image property. You can set the pin color and drop animation.
Don't forget about the leftCalloutAccessoryView and the rightCalloutAccessoryView properties of MKAnnotationView that can be used to customize the callout view.
The title and subtitle are displayed when a pin is selected on the map. The subtitle simply falls below the title.
MKPinAnnotationView is simply an specialized form of MKAnnotationView that knows how to draw a pin (and a shadow) and also allows setting the pin color. It's the only built-in annotation view with an image, you have to make your own if you want something different (but it's very easy to do).

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