Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom CallOut not displayed correctly in ios6?

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 enter image description here

In Ios6 This one not coming properly as like in ios5. for example enter image description here

like image 317
Balu Avatar asked Nov 28 '12 05:11

Balu


1 Answers

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.

like image 102
08442 Avatar answered Nov 12 '22 11:11

08442