gpt4 book ai didi

ios - 旋转注释自定义图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:15:49 26 4
gpt4 key购买 nike

<分区>

我显然不明白这一点。我正在尝试找出如何旋转 map 注释的自定义图像。即多个图标指向不同的方向。我已经遍历了一大堆飞机数据,我想简单地显示飞机的前进方向。

查看我设法拼凑起来的代码,至少有一半可以正常工作,并提供有关如何根据变量转换图像的建议性想法。

循环数据的抽象 View

             NSMutableArray *locations = [[NSMutableArray alloc]init];
CLLocationCoordinate2D location;

MKPointAnnotation *myAnn;
myAnn = [[MKPointAnnotation alloc]init];
location.latitude = nLatitudeFloat;
location.longitude = nLongitudeFloat;
myAnn.coordinate = location;
myAnn.title = nRealname;

//Add the Annotation object to the list so when the map is presented all points are listed on the map.
[locations addObject:myAnn];

//[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
[self.mapView addAnnotations:locations];

注解的更新:

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// If it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]]) return nil;

// Handle any custom annotations.
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
// Try to dequeue an existing pin view first.
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];

if (!pinView)
{
// If an existing pin view was not available, create one.
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
pinView.canShowCallout = YES;

pinView.image = [UIImage imageNamed:@"airplane21.png"] ;
pinView.calloutOffset = CGPointMake(0, 32);
pinView.transform = CGAffineTransformMakeRotation(30); <------AT THE MOMENT I HAVE JUST HARD CODED THIS TO SEE IF IT WORKS. IT ROTATES THE ENTIRE ANNOTATION

// Add a detail disclosure button to the callout.
//UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//pinView.rightCalloutAccessoryView = rightButton;

// Add an image to the left callout.
UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"airplane21.png"]];
pinView.leftCalloutAccessoryView = iconView;
iconView.transform = CGAffineTransformMakeRotation(30);
} else {
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}

有什么想法吗?

这个我看过了。我只是不确定它是否合适。 Rotate annotation image on MKMapView

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com