Gee*_*eet 1 objective-c mkmapview mkannotation ios mkoverlay
我需要创建一个地图视图界面,类似于iOS中的OLA Cabs应用程序.我真正想做的是在mapView上修复叠加层,并允许用户在其上滚动地图视图.因此,可以在用户想要的任何位置修复叠加层,我在iOS和MapKit中搜索了大量有关叠加层的内容,但无法实现.如果有人可以给我实现这个的提示,我将非常感激.这是屏幕的快照

这里注释保持固定,您可以在其上移动地图视图,这样当您停止mapview时,叠加层将指向新位置,您停在那里

创建修复MKAnnotation和图像视图对象,以在"地图"视图中设置位置更改效果的动画.
@property (nonatomic, strong) CustomAnnotation *fixAnnotation;
@property (nonatomic, strong) UIImageView *annotationImage;
Run Code Online (Sandbox Code Playgroud)
在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"]];
Run Code Online (Sandbox Code Playgroud)
现在,在拖动地图视图并添加看起来像注释的图像时,必须删除图像.完成后添加注释并从Map View中删除图像.
- (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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1578 次 |
| 最近记录: |