use*_*457 6 iphone cocoa-touch objective-c mapkit ios7
我正在开发适用于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];
Run Code Online (Sandbox Code Playgroud)
然后实现mapView下面的委托方法...
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2204 次 |
| 最近记录: |