当用户平移地图时,iOS 6中的我的地图注释不会保持旋转状态

时间:2013-01-09 00:27:48

标签: iphone ios6 annotations rotatetransform

在回答类似问题时,用户说要做以下事情:

对此的修复是在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
    }
}

最初的答案是将bug放在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;
}

感谢您的帮助。

谢谢, 马特

1 个答案:

答案 0 :(得分: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;
    }

希望能帮助那些遇到同样问题的人。