我正在开发一个iOS 7的应用程序,并尝试将地图从白天模式切换到夜晚模式,或者从夜晚模式切换到白天模式。在iOS 7文档中,我没有找到相关的API来实现这个功能。
我正在开发一个iOS 7的应用程序,并尝试将地图从白天模式切换到夜晚模式,或者从夜晚模式切换到白天模式。在iOS 7文档中,我没有找到相关的API来实现这个功能。
MKMapKit
的内置功能,所以如果没有自己实现,你所要求的是不可能的。如果你要自己实现,最好的方式就是找到一组“夜间模式”的地图瓦片源,然后使用MKTileOverlay
类(iOS 7中新增)完全替换地图内容。// Put this in your -viewDidLoad method
NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
//This is the important bit, it tells your map to replace ALL the content, not just overlay the tiles.
overlay.canReplaceMapContent = YES;
[self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];
mapView
代理方法...- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
}
此链接为苹果官方提供的MKTileOverlay类的参考文档。