As i want to implement the custom call out in the mkmapview i am using these classes CalloutMapAnnotationView.h and CalloutMapAnnotationView.m
I have extracted these classes from the following links
https://github.com/asalom/Custom-Map-Annotation-Callouts/blob/master/Classes/CalloutMapAnnotationView.h
https://github.com/asalom/Custom-Map-Annotation-Callouts/blob/master/Classes/CalloutMapAnnotationView.m
These work fine in ios5 but in ios6 when i am clicking on the call out the map view is moving and call out is not showing correctly as shown in the below figures while i was zooming also its not coming correctly i have tried several ways to get rid out of this problem by checking the version of os and tried to change the some of the methods in the classes but of not use.
After implementing these in ios5 map view coming like this
In Ios6 This one not coming properly as like in ios5. for example
I too have faced the same problem in iOS 6
using these classes. These changes worked for me:
1) Change in this method:
This method you will implement in your map view class
(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView*)view
as following order of lines
self.selectedAnnotationView = view;
[self.mapView addAnnotation:self.calloutAnnotation];
2) In CalloutMapAnnotationView.m file
- (void)adjustMapRegionIfNeeded in this method first 5 lines like bellow
CGFloat xPixelShift = 0;
if ([self relativeParentXPosition] < 38) {
xPixelShift = 38 - [self relativeParentXPosition];
} else if ([self relativeParentXPosition] > self.frame.size.width - 38) {
xPixelShift = (self.frame.size.width - 38) - [self relativeParentXPosition];
}
3) In same class CalloutMapAnnotationView.m - (void)drawRect:(CGRect)rect
in this method afterCGFloat parentX = [self relativeParentXPosition];
line and above rect = self.bounds;
this line
add following lines
if ([self relativeParentXPosition] < 38) {
parentX = 38;
} else if ([self relativeParentXPosition] > self.mapView.frame.size.width - 38) {
parentX = [self relativeParentXPosition]-25;
}
4) In same class CalloutMapAnnotationView.m.
- (void)didMoveToSuperview {
[super didMoveToSuperview];
[self.superview bringSubviewToFront:self];
}
You can use directly the above classes and use them they work fine in both iOS 5 & iOS 6. You should make necessary changes according to your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With