MKMapView에 추가 된 이미지를 주석으로 회전하려고합니다. 그것은 분명 나에게있는 UIImageView를 이미지를 할당하고 안 annotationView.image 같은 오류를 제공MKMapView에서 주석 이미지 회전
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation
{
if (! [annotation isKindOfClass:[IGAMapAnnotation class]])
{
//return default view if annotation is NOT of type IGAMapAnnotation...
return nil;
}
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"IGAMapAnnotation"];
if (annotationView == nil)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"IGAMapAnnotation"];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
else
{
annotationView.annotation = annotation;
}
IGAMapAnnotation *myLocation = (IGAMapAnnotation *) annotation;
// THIS IS IT!
if ([myLocation.type isEqual: @"PLANE"]) {
UIImage *planeImage = [UIImage imageNamed:@"planetracked.png"];
UIImageView *planeImageView = [[UIImageView alloc]initWithImage:planeImage];
planeImageView.transform = CGAffineTransformMakeRotation(M_PI_2);
annotationView.image = planeImageView;
}
return annotationView;
}
:
이
는 코드입니다. 나는 단지 이미지를 회전시키는 다양한 방법을 시도했다. 예를 들면 다음과 같다 :- (UIImage *)rotateImage:(UIImage *)image onDegrees:(NSString *)heading {
double angle = [heading doubleValue];
CGSize s = {image.size.width, image.size.height};
UIGraphicsBeginImageContext(s);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, 0,image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextRotateCTM(ctx, 2*M_PI*angle/360);
CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width, image.size.height),image.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
그들은 작동하지 않는다 - 어떤 이미지도지도 상에 나타나지 않는다.
누구나 MKMapView에서 주석 이미지를 회전하는 방법을 알고 있습니까?
백만 감사드립니다!
'annotationView.image = planeImageView; 대신 틀린 것은'[annotationView addSubview : planeImageView];'를 시도해보십시오. 또한'type'이 "PLANE"이 아닌 경우 이미지가 설정되지 않기 때문에 주석이 보이지 않을 것입니다. 그래서'else' 부분을 추가해야합니다. – Anna
안나. 정말 고맙습니다. 그것은 트릭을합니다. 이미지가 회전됩니다. 이제 문제는 주석이 업데이트 될 때 맵에서 제거하는 것입니다 (제 경우에는 5 초마다 업데이트됩니다). 나는 이것을 사용하고있다 :'[self.mapView removeAnnotations : mapLocations];'그러나 이미지는 제거되지 않는다. 게다가 좌표가 바뀌지 않았지만 맵의 다른 위치에 나타날 수 있다는 것을 알았습니다. 이유가 궁금합니다. 정말 고맙습니다! –