是否可以将MKMapView
排列在另一个MKMapView
的顶部,并且顶部具有一定的透明度,因此您可以看到底部。进一步,当用户滑动时,我希望顶部和底部的地图都可以滚动或放大。
我发现标准地图太简单了,卫星地图太紧张了,希望将它们组合起来才能产生效果。
有什么想法吗?
答案 0 :(得分:0)
您可以做到这一点,完全没有问题。正如您已经描述的,只需在窗口中放置一个MKMapView并在其顶部放置第二个。假设我们将它们称为_map1和_map2,后者位于_map1之上。 MKMapViewDelegate协议将在用户滚动/移动/缩放_map2时通知您,因此您可以告诉_map1显示_map2的相同可见区域。
在我的示例中,我使用滑块设置_map2的透明度。
#import "ViewController.h"
@import MapKit;
@interface ViewController () <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *map1;
@property (weak, nonatomic) IBOutlet MKMapView *map2;
@property (weak, nonatomic) IBOutlet UISlider *alphaSlider;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_map1 setMapType:MKMapTypeSatellite];
[_map2 setMapType:MKMapTypeStandard];
[_map2 setAlpha:0.5];
[_map2 setDelegate:self];
[_alphaSlider addTarget:self action:@selector(sliderChanged) forControlEvents:UIControlEventAllEvents] ;
_alphaSlider.value = _map2.alpha;
}
- (void)mapViewDidChangeVisibleRegion:(MKMapView *)mapView
{
// _map2 is on top and will receive visible region updates, i.e. the user scrolled/moved/zoomed the map
// just pass the new region to _map1 so it will be similar to that one of _map2
[_map1 setRegion:_map2.region];
}
- (void)sliderChanged
{
[_map2 setAlpha:_alphaSlider.value];
}