我正在开发一个适用于 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];
}
}
如需完整参考,请参阅https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKTileOverlay_class/Reference/Reference.html https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKTileOverlay_class/Reference/Reference.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)