0

在回答类似问题时,用户说要执行以下操作:

解决方法是在 viewForAnnotation 方法中执行以下操作:

// iOS6 BUG WORKAROUND !!!!!!!
if (is6orMore) {
     [annotationView setTransform:CGAffineTransformMakeRotation(.001)]; //any small positive rotation
}

我试过把这段代码放在各处,当地图被平移时,我的注释仍然会旋转。这是我的代码。

每当地图旋转时,我都会调用此方法

-(void)rotateAnnotations {

    for (id<MKAnnotation> annotation in self.mapView.annotations)
    {
        MKAnnotationView* annotationView = [self.mapView viewForAnnotation:annotation];

        [annotationView setTransform:CGAffineTransformMakeRotation(- self.mapRotationRadians)];
        if ([annotation isKindOfClass:[FlagAnnotation class]]) {
            [annotationView setSelected:YES animated:NO];
        }
         [annotationView setNeedsDisplay];  //ios6
    }
}

最初的答案说是在 viewForAnnotation 方法中解决代码问题。这是那个代码。

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

   if ([annotation isKindOfClass:[FlagAnnotation class]]) {

        // once flag is set allow for doubleTap zoom
        [self.mapView addGestureRecognizer:doubleTap];

        static NSString *AnnotationViewID = @"annotationViewID";
        MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

        if (!annotationView)
        {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
            annotationView.image = [UIImage imageNamed:@"FlagRed"];
            annotationView.draggable = YES;
            [self updateFlagCoordinate:(MKPlacemark *)annotationView.annotation];
            return annotationView;

        }
        else {
            [self updateFlagCoordinate:(MKPlacemark *)annotationView.annotation];
            annotationView.annotation = annotation;
        }

        // iOS6 BUG WORKAROUND !!!!!!!
        if (osVersion() >= 6) {
            [annotationView setTransform:CGAffineTransformMakeRotation(.001)];
        }

        return annotationView;
    }
    return nil;
}

我会很感激你的帮助。

谢谢,马特

4

1 回答 1

2

在玩了更多代码之后,我发现我确实在 viewForAnnotation 的错误位置修复了错误。我在这里有代码:

if (!annotationView)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
        annotationView.image = [UIImage imageNamed:@"FlagRed"];
        annotationView.draggable = YES;
        [self updateFlagCoordinate:(MKPlacemark *)annotationView.annotation];
        return annotationView;

    }
    else {
        [self updateFlagCoordinate:(MKPlacemark *)annotationView.annotation];
        annotationView.annotation = annotation;
    }

    // iOS6 BUG WORKAROUND !!!!!!!
    if (osVersion() >= 6) {
        [annotationView setTransform:CGAffineTransformMakeRotation(.001)];
    }

    return annotationView;

我需要把它放在这里:

if (!annotationView)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
        annotationView.image = [UIImage imageNamed:@"FlagRed"];
        annotationView.draggable = YES;
        [self updateFlagCoordinate:(MKPlacemark *)annotationView.annotation];

        // iOS6 BUG WORKAROUND !!!!!!!
        if (osVersion() >= 6) {
            [annotationView setTransform:CGAffineTransformMakeRotation(.001)];
        }
        return annotationView;
    }

希望这可以帮助有同样问题的人。

于 2013-01-10T20:59:55.673 回答