本文介绍了自定义CallOut在ios6中无法正确显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我想在mkmapview中实现自定义调用,我使用这些类CalloutMapAnnotationView.h和CalloutMapAnnotationView.m

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

这些在ios5中工作正常,但在ios6中点击在呼叫时,地图视图正在移动,并且呼叫未正确显示,如下图所示,而我正在缩放也不正确我已尝试过通过检查操作系统的版本来解决这个问题的方法,并尝试更改类中的一些方法但不使用。

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.

实现这些之后在ios5地图视图中来自这样的

After implementing these in ios5 map view coming like this

在Ios6中这个没有像ios5那样正常。例如

In Ios6 This one not coming properly as like in ios5. for example

推荐答案

我也在使用这些类在 iOS 6 中遇到了同样的问题。这些更改对我有用:

I too have faced the same problem in iOS 6 using these classes. These changes worked for me:

1)此方法的更改:

此方法将在您的方法中实施map视图类

This method you will implement in your map view class

(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView*)view

按以下顺序排列

self.selectedAnnotationView = view;

[self.mapView addAnnotation:self.calloutAnnotation];

2)在CalloutMapAnnotationView.m文件中

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)在同一个类中CalloutMapAnnotationView.m - (void)drawRect:(CGRect)rect 在此方法中 CGFloat parentX = [self relativeParentXPosition];

3) In same class CalloutMapAnnotationView.m - (void)drawRect:(CGRect)rect in this method afterCGFloat parentX = [self relativeParentXPosition];

行及以上 rect = self.bounds; 此行
添加以下行

line and above rect = self.bounds; this lineadd following lines

    if ([self relativeParentXPosition] < 38) {

       parentX = 38;

   } else if ([self relativeParentXPosition] > self.mapView.frame.size.width - 38) {

       parentX = [self relativeParentXPosition]-25;

   }

4)在同一个类CalloutMapAnnotationView.m。

4) In same class CalloutMapAnnotationView.m.

- (void)didMoveToSuperview {
        [super didMoveToSuperview];
        [self.superview bringSubviewToFront:self];
    }

你可以直接使用上面的类并使用它们在iOS上都可以正常工作5& iOS 6.
您应该根据您的要求进行必要的更改。

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.

这篇关于自定义CallOut在ios6中无法正确显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:04