需要在IOS中添加一个固定的覆盖像在mapview上

我需要创build一个地图视图界面,​​类似于iOS中的OLA驾驶室应用程序。 我真正想要做的是修复mapView的覆盖,并允许用户滚动地图视图。 为了使覆盖层可以固定在用户想要的任何位置,我在iOS和MapKit中search了很多关于覆盖层的信息,但是无法实现。 如果有人可以给我提示,以实现这一点,我将非常感激。 这是屏幕快照

在这里输入图像说明

在这里,注释保持不变,您可以将地图视图移到地图视图上,这样,当您停止地图视图时,覆盖图将指向新的位置,停止的位置

点击这里下载演示…

在这里输入图像说明

创build一个修复MKAnnotation和图像视图对象来animation地图视图中的位置更改效果。

 @property (nonatomic, strong) CustomAnnotation *fixAnnotation; @property (nonatomic, strong) UIImageView *annotationImage; 

viewDidLoad()方法中添加下面的代码:

  // Fix annotation _fixAnnotation = [[CustomAnnotation alloc] initWithTitle:@"Fix annotation" subTitle:@"Location" detailURL:nil location:self.mapView.userLocation.coordinate]; [self.mapView addAnnotation:self.fixAnnotation]; // Annotation image. CGFloat width = 64; CGFloat height = 64; CGFloat margiX = self.mapView.center.x - (width / 2); CGFloat margiY = self.mapView.center.y - (height / 2) - 32; // 32 is half size for navigationbar and status bar height to set exact location for image. _annotationImage = [[UIImageView alloc] initWithFrame:CGRectMake(margiX, margiY, width, height)]; [self.annotationImage setImage:[UIImage imageNamed:@"mapannotation.png"]]; 

现在必须在拖动地图视图并添加看起来像注释的图像时移除图像。 完成后,添加注释并从地图视图中删除图像。

 - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { NSLog(@"Region will changed..."); [self.mapView removeAnnotation:self.fixAnnotation]; [self.mapView addSubview:self.annotationImage]; } - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { NSLog(@"Region did changed..."); [self.annotationImage removeFromSuperview]; CLLocationCoordinate2D centre = [mapView centerCoordinate]; self.fixAnnotation.coordinate = centre; [self.mapView addAnnotation:self.fixAnnotation]; } 

它不是一个地图注记叠加层,它是一个普通的UIImageView ,它放置在MKMapView上 ,它总是用来获得地图中心点的lat-long。

希望这将是一个简单的方法来实现你的目标。

@Kampai为您添加了相同的代码。