需要在IOS中的mapview上添加固定叠加层 [英] Need to add a Fixed Overlay like on mapview in IOS
问题描述
我需要创建一个地图视图界面,类似于iOS中的OLA Cabs应用程序。我真正想做的是在mapView上修复叠加层,并允许用户在其上滚动地图视图。因此,可以在用户想要的任何位置修复叠加层,我在iOS和MapKit中搜索了很多关于叠加层的内容,但无法实现。如果有人可以给我实现这个的提示,我将非常感激。这是屏幕的快照
I need to create a map view interface, which is something similar to the OLA Cabs Application in iOS. What I exactly wanna do is to fix an overlay on mapView and allow the user to scroll the map view across it. So that the overlay can be fixed at any location the User wants it to, I searched a lot about overlays, in iOS and MapKit, but couldn't make it possible. If some one can give me tips for achieving this I would be really grateful. Here is a snapshot of the screen
此处注释保持不变,您可以在其上移动地图视图,这样当您停止地图视图时,叠加层将指向新位置,你停在哪里
Here the annotation remains fixed and you can move the map view across it, So that when you stop the mapview, the overlay will be pointing to the new location, where you stopped
推荐答案
请点击这里下载演示......
Click here to download demo...
创建修复 MKAnnotation
和图像视图对象,以在Map中设置位置更改效果的动画查看。
Create a fix MKAnnotation
and image view object to animating the location change effect in Map view.
@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"]];
现在,当您拖动地图视图并添加看起来像注释的图像时,必须删除图像。完成后添加注释并从地图视图中删除图像。
Now have to remove image when you drag a map view and add image which looks like an annotation. And after completion of that add annotation and remove image from 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];
}
这篇关于需要在IOS中的mapview上添加固定叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!