I have an interesting challenge. I need to create a callout for an MKAnnotation that has a slightly custom look on my map. It has a right accessory view, but it also requires a button in the bottom center of the callout.
Is there a way to create a button and place it on the callout or is it possible to move the location of the left accessory so that it is in bottom center?
Use MKAnnotationView, as you've tagged in your question. Loads of resources and info if you search - this post seems like a good start to making a custom callout. You'll be able to add the changes to the look as you outline in your question.
If you want to change any aspect of the look and behaviour of the map callout you will need to provide a custom implementation.
Related
Im having some issues styling my MKAnnotation callout bubble. Originally I had a standard callout that consisted of just a title, subtitle and leftCalloutAccessoryView. This created the following callout:
This worked fine until it was decided that the subtitle should also contain a series of five images that show the business's average ratting among user reviews. This was done by creating a separate view and passing it as the detailCalloutAccessoryView. This produced the following callout bubble:
For some reason when the view is passed to the detailCalloutAccessoryView the callout view is given a weird border around all UI components that create unwanted whitespace around the leftCalloutAccessoryView and between the title and subtitle. How can I remove this white space? I want the business's average ratting inside the subtitle and proper spacing between the title and detailCalloutAccessoryView. How can this be achieved? Is it possible to do so without creating the callout from scratch?
Without code, it is hard to give a detailed answer.
But I found a hint that may solve your problem in this post:
Apparently, MapKit sets translatesAutoresizingMaskIntoConstraints to false, when you set a view to detailCalloutAccessoryView.
This means that you have to set auto layout constraints by your own.
I suggest you create one custom pin representing the Bubble (BubblePin), and each time the user selects one regular pin, you add the BubblePin at the same position of the last selected regular pin.
So adding one additional pin and switching its position according to the user selection will solve the problem, just make sure to add the BubblePin some offset so it won't be right on top of the regular one.
Our UIView contains a MapBox map. At certain moments during our apps lifespan we display a UIView on top of the Map.
This view had a transparant background and a couple of controls inside it. What we want is to be able to drag the map on the spots where the view is transparent. (It should basically pass through the gestures to the view below it..which is the map).
To get a basic picture of what we try to accomplish: think of a map and above it is a view which shows a big + sign. What we want is when we drag the actual sign...nothing happens. But when you drag in the empty corners, it should drag the map.
Any ideas how to accomplish that?
Check out -[UIView userInteractionEnabled] and set it to NO for the transparent view. Be sure to set it to YES for the control subviews. That should do the trick.
I'm making a custom MKAnnotation where I return a UIButton. My question is if there's any way to make the clickable area of that UIButton larger than the actual button? I've tried adding the button to a larger UIView with a tapGestureRecognizer, but it dosen't seem that the gestureRecognizer is ever called.Any thoughts?
Edit:
To clarify: It is the annotation "pin" which is custom, not the "pop-up-view". I want the user to easily be able to hit the pin :-)
I'm implementing a map feature in my app where I allow the user to set their current location by panning around.
All this time, I want to have an MKAnnotation in the centerCoordinate. So what I want to do is keep track of when the map's centerCoordinate changes and change the annotation's coordinate correctly. The behaviour would be similar to that of Uber, Hailo and others.
I tried a time based implementation where every 0.00001s the centerCoordinate would be checked and the annotation would also be moved. But if the map isn't flicked gently, the annotation jumps from one place to another which doesn't make for a good UI.
Another implementation I tried is by way of gesture recognisers and the delegate methods of MKMapView (regionDidChange/regionWillChange). This, again, makes for a very abrupt transition.
Can anyone please advise me on how to do this better?
I suggest not using an actual id<MKAnnotation> at all (at least for this "current location setting" mode).
Instead:
Add a view (eg. UIImageView) containing an image of a pin (or whatever icon you like) in front of the map view.
This pin view should not be a subview of the map view.
The pin view should be a subview of the same view that the map view is a subview of (eg. both should be subviews of the same superview).
The pin view should be sized and positioned such that it appears above the center of the map view (you could make the pin view have the same frame and the same autolayout/autoresizing logic as the map view so they stay visually synchronized regardless of screen size or orientation).
If using a UIImageView, set its content mode to "center" and background color to "clear" (default is clear).
The pin view should have user interaction disabled on it so that the user can still interact with the map view behind it. As the user pans or zooms the map view, the pin view in front will seem to move instantly.
If necessary, the app can get the location coordinates from mapView.centerCoordinate in the regionDidChangeAnimated: MKMapViewDelegate method (or pan/pinch gesture recognizers) or only when the user says they're done positioning. I don't recommend using a timer (especially every 0.00001s) to query the current center coordinate.
When the user indicates that the current position is where they want to finally place the annotation, you can then create and add an actual annotation at that coordinate and hide the "location setting mode" pin view.
I want to add multiple pins on map which should remain animated continuously. Below are sample images which I want to use as Pin,
Is there any possible way to get this type of animated pin within MapKit? If possible then please suggest me appropriate way for it.
As per my knowledge it is quite tough to implement. You can easily implement animation on any UIImageView but when you add any image on custom image then you can change custom pin image via using KVO or via NSTimer.
Please follow Animation with MapView Custom Pin link to better understanding with custom pin annotation.
You can change pin image too after a certain period of time like as Zooming change pin image
and Custom pin animation - MKMapView.
I hope it will help you to better understanding. Thanks
You could create a custom MKAnnotationView and give it a UIImageView as a subview.
Then, split the GIF into separate frames, to use in the UIImageView, as documented in this SO question.