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 在这里输入图像描述

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 after CGFloat 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.


只要你可以添加nsstring标题和nstring字幕,_name就是你想要的标题。

- (NSString *)title {
    return _name;
}
- (NSString *)subtitle {
    return [NSString stringWithFormat:@"%f, %f", _coordinate.latitude, _coordinate.longitude];
}
链接地址: http://www.djcxy.com/p/11528.html

上一篇: 两个连接边界的形态分离

下一篇: Custom CallOut在ios6中显示不正确?