mkmapview custom callout bubble ios6 - ios

I'm encountering a mystery issue when selecting a pin in the mapview iOS6
BTW, it works correctly in iOS 5, i'm not sure what they changed in the map of iOS 6 that produce this issue.
NOTE that when I click on the map, the callout directly go over the pins and shows correctly
any help/clue would be appreciated,
Thanks in advance

the answer might vary a bit depending on how you're implementing your custom callout bubble. This was/is the solution I'm using: Customize the MKAnnotationView callout and I ran into the exact same problem.
Basically, everytime the callout is going to show, I had to bring the subview to the front.
In this case, my custom callout bubble is a class called 'BaseCalloutView' which contains a UIView as its ContentView property (as you can see in the UML diagram at the link above). When the annotation is selected, it triggers the 'animateIn' function of the BaseCalloutView, into which I added:
[self.superview bringSubviewToFront:self];
As I mentioned, your mileage may vary depending on how you're implementing the custom callout bubble. I can provide you with the full code if needed - but to be honest 90% of my code is from the link above.

This solution didn't work for me, however the one did:
Custom Annotation View do not work on iOS6
Sorry not sure how to link answers properly.

In IOS 5 and IOS 6 , I try this and it's ok
the pin never overlap CalloutView.
I use custom calloutview , in file Base calloutView I add this :
- (void)didMoveToSuperview {
[super didMoveToSuperview];
[self.superview bringSubviewToFront:self];
}

I am using same code base, got same problem. [self.superview bringSubviewToFront:self]; doesn't work for me, not matter where did I put it. [annimateIn] or [didMoveToSuperView] or [layoutIfNeeded]
Because this problem went away by finger moving the map a little bit, so I found it is very easy to simulate this effect by put code in - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view. The offset is very small, no visual movement can be noticed at all.
CLLocationCoordinate2D newCenterCoordinate = {self.mapView.region.center.latitude + 0.0000001,
self.mapView.region.center.longitude + 0.0000001};
[self.mapView setCenterCoordinate:newCenterCoordinate animated:NO];

Related

iOS 11 MKAnnotationView prepareForReuse dismiss the pin view in Map view

what I want to do is when I deselect an pin, the pin view change it's UI back to unselected state(e.g change color of background of the pin)
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
//do something;
XLMapItemAnnotation* mapItem = [self annotationForView:view];
[view prepareForReuse];
}
by having this code, when I run the app in iOS 11, if I deselect a pin, the pin disappear in the map view totally. and if I remove the prepareForReuse, everything would be fine.
and the some code if I run the app in iOS 10, everything is fine, no pin get disappeared.
can sbd give me a hint, what could be wrong?
You should not call -prepareForReuse yourself, it's intended for MapKit to call itself.
As #Tim Johnsen said, -prepareForReuse is intended for MKAnnotationView's reuse mechanism, you should not call it yourself.
In iOS 11, MapKit introduce clustering algorithm for MKAnnotationView(But after some try, I found it cause strange behavior sometimes). In this case, MKAnnotationView.isHidden is set as true by default. So after you invoking -prepareForReuse, MKAnnotationView is hidden.
If you want to change color of the pin, just change pinTintColor property directly, or use a function to reset all properties as needed.

Customizing Mapbox Callout with HTML on iOS

I am trying to implement a custom callout using MapBox on iOS. When the user presses on the marker I would like a callout to display a UIWebView rather than a left and right accessory view and the title with text only.
I have searched through the SDK documentation and cannot find a simple way to access the view of the annotation title so I can set it to a UIWebView.
I started off by trying to access the annotation layer to see if I could make changes, such as:
RMAnnotation *annotation = [[RMAnnotation alloc] initWithMapView:mapView coordinate:CLLocationCoordinate2DMake(56.0,-4.0) andTitle:#"test"];
annotation.userInfo = #"test";
RMMapLayer *layer = annotation.layer;
layer.backgroundColor = [UIColor blackColor].CGColor;
However, when I press on the marker the annotation bubble is still white.
I have searched through the SDK to try to understand the relationship between the RMAnnotation and RMMarker classes and how they interact but think my understanding is flawed and hence I am not getting anywhere.
If anyone can help point me in the right direction that would be appreciated!
Ok, I figured out a way to make this work. Its a little of a 'hack' but it works really well for my purposes so I thought I would share. Please comment if you have a better idea and also tell me if this is not a great way to do it.
I checked the SDK source code and the RMMapView passes the SMCalloutView object the title, subtitle and left/right accessory views. When I checked the SMCalloutView code there is the ability to provide a custom callout by passing a UIView to contentView, but the RMMapView doesn't provide for passing this. My fix was to synthesize the SMCallout (_currentCallout) so that I can access contentView from my ViewController and set contentView to a UIWebView. I chose to create a new delegate method in RMMapViewDelegate called aboutToDisplayAnnotation that provides me with the opportunity to swap in my UIWebView before the callout is drawn to the screen, but I guess a better way might have been to rewrite the selectAnnotation method in RMMapView.

iOS UIView/UIScrollView overlay with zoom capability

I have a UIView/UIScrollView with non rectangular sections, let's call them room plans.
The UIView/UIScrollView should be zoomable.
When the user clicks to a non rectangular region/room, I should be able to detect which region was clicked and let's say open up the detailed floorplan of that particular room.
The problem is that
1. when I zoom in and out, the 'button' size must change.
2. the button is not rectangular.
see an example of what I am trying to implement in iOS.
http://www.occc.net/ifp/
Any ideas of how to approach this problem are welcome.
Thank!
I was trying to do a similar thing there. What i did was use a UIImageView within a UIScrollView and load the image in the UIImageView.
I did this in my viewDidLoad :
scrollMap.minimumZoomScale=1;
scrollMap.maximumZoomScale=2.0;
scrollMap.delegate=self;
Then added this function :
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imgMap;
}
This made the image inside the scrollview zoomable with the aspect ratio of the scrollview. It worked for me. You can try, this might work for you too.
Thanks.
you can use OBShapedButton, i found on github and i have used in more than three apps.
It is very easy to implement you should try this.....

MKMapKit disalow deselection of callout bubble

I would like to know how I can make sure that a callout bubble can't get deselected on a MKMapView.
Whenever I press on the map (background), this view:
Turns to:
Which I do not want to allow. Yet I do want to keep the callOutButton support.
You could just programmatically select your annotation whenever annotations get deselected (using the corresponding delegate method). If you don't animate this selection then it looks as if the annotation never got deselected in the first place.
Example:
// MKMapView Delegate
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
// Replace "myAnnotation" with whichever annotation you need to remain selected
[mapView selectAnnotation:self.myAnnotation animated:NO];
}
I tried this in a test project and it works fine (it doesn't flicker or anything). It's not exactly disabling deselection but the resulting effect is the same, so it might be a good workaround.

Map Annotations in iOS 6 don't stay rotated when user pans the map

Would really love an answer to this question https://devforums.apple.com/message/723468. I can't post the details because its about iOS 6 and is Confidential per Apple.
Please post the answers/comments to the Apple Dev forums post and let me know about it here.
EDIT: Since iOS6 is officially released:
In my pre-ios6 code I'm doing this to rotate the map when the user location moves:
//this is in my MKMapViewDelegate
-(void) rotateMap:(MKMapView *)mapViewTmp forLocation:(MKUserLocation *) userLocation {
...
//calculate needed rotation
...
[mapViewTmp setTransform:CGAffineTransformMakeRotation(lastRotation)]; //rotate the MKMapView
for (id<MKAnnotation> annotation in mapViewTmp.annotations) {
MKAnnotationView* annotationView =[mapViewTmp viewForAnnotation:annotation];
[annotationView setTransform:CGAffineTransformMakeRotation(-lastRotation)]; //counter rotate the Annotation Views
[annotationView setNeedsDisplay]; //ios6
}
}
And this worked fine (1000s of users).
In ios6 however (I updated Xcode/sdk on 9/4/2012), the annotation views do not maintain this rotation (for example if map is panned). They flip back to their non rotated state (which, since my map is rotated means they show text at an angle instead of horizontal).
The code does temporarily rotate the annotations so their text appears horizontal, but if map is panned (and their seem to be other causes as well) then the annotations flip to their non-rotated state and my annotation text appears at an angle relative to the rotated map.
What is the correct way to rotate an MKAnnotationView so that it stays rotated in IOS6? What has changed in MKMapView that caused the change?
The fix for this is to do the following in the viewForAnnotation method:
// iOS6 BUG WORKAROUND !!!!!!!
if (is6orMore) {
[annotationView setTransform:CGAffineTransformMakeRotation(.001)]; //any small positive rotation
}
This was posted as a comment by me in the original question and then posted by cristis as an answer (referencing my comment), but I'm posting and accepting my own answer since it was me that came up with it. Did that make sense?
This was posted as a comment, I'm re-posting it as an answer so anyone can see it easily (and waste less time trying to figure it out).
And the fix is===>in viewForAnnotation method:
// iOS6 BUG WORKAROUND !!!!!!!
if (is6orMore) {
[annotationView setTransform:CGAffineTransformMakeRotation(.001)];
}
I saw the same thing. Here's the fix:
Set YOUR transform on the child of the MKAnnotationView, so in pseudo-ish code:
view.child.transform = CGAffineTransformMakeRotation(0.3);
Let them have control of the annotation view and take control of your view subtree. Transforms concatenate and you'll inherit whatever they do in position. Works for me on iOS 6.

Resources