- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我认为 iOS 7 的 MKMapSnapshotter
将是拍摄 MKMapView
快照的简单方法,好处是您可以在不将 map 加载到 View 中的情况下执行此操作.尽管添加图钉和叠加层似乎需要更多工作(因为需要核心图形)。 WWDC 视频提供了一个很好的示例,说明如何通过添加 MKAnnotationView
创建 MKMapSnapshotter
。
但是,对于核心图形经验不多的人来说,如何从 MKPolylineRenderer
创建 MKMapSnapshotter
并不是很明显。
我试过这样做,但是路径不准确。它准确地绘制了大约 10% 的线,但随后绘制了笔直的路径的其余部分。
这是我的代码:
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:snapshotOptions];
[snapshotter startWithQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
completionHandler:^(MKMapSnapshot *snapshot, NSError *error)
{
if (error == nil)
{
UIImage *mapSnapshot = [snapshot image];
UIGraphicsBeginImageContextWithOptions(mapSnapshot.size,
YES,
mapSnapshot.scale);
[mapSnapshot drawAtPoint:CGPointMake(0.0f, 0.0f)];
CGContextRef context = UIGraphicsGetCurrentContext();
//Draw the points from the MKPolylineRenderer in core graphics for mapsnapshotter...
MKPolylineRenderer *overlay = (MKPolylineRenderer *)[self.mapView rendererForOverlay:[_mapView.overlays lastObject]];
if (overlay.path)
{
CGFloat zoomScale = 3.0;
[overlay applyStrokePropertiesToContext:context
atZoomScale:zoomScale];
CGContextAddPath(context, overlay.path);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextStrokePath(context);
}
UIImage *pathImage = UIGraphicsGetImageFromCurrentImageContext();
[map addMapIcon:pathImage];
UIGraphicsEndImageContext();
}
}];
有没有人有一个很好的可行示例来说明如何执行此操作?
最佳答案
刚遇到同样的问题,这段代码似乎有效:
UIImage * res = nil;
UIImage * image = snapshot.image;
UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
[image drawAtPoint:CGPointMake(0, 0)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [COLOR_FLASHBLUE CGColor]);
CGContextSetLineWidth(context,2.0f);
CGContextBeginPath(context);
CLLocationCoordinate2D coordinates[[polyline pointCount]];
[polyline getCoordinates:coordinates range:NSMakeRange(0, [polyline pointCount])];
for(int i=0;i<[polyline pointCount];i++)
{
CGPoint point = [snapshot pointForCoordinate:coordinates[i]];
if(i==0)
{
CGContextMoveToPoint(context,point.x, point.y);
}
else{
CGContextAddLineToPoint(context,point.x, point.y);
}
}
CGContextStrokePath(context);
res = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
关于ios - 使用 MKPolylineRenderer 创建 MKMapSnapshotter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22692449/
我正在开发一个几乎复制 Apple map 应用程序行为的应用程序。当我触摸一条路线时,我需要将其颜色更改为蓝色并将其他颜色更改为灰色。有没有一种有效的方法来实现这一点而不必删除覆盖并再次添加它们?谢
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id )overlay{ if ([overlay is
我在使用 map 应用程序,我想问一下如何在不删除并重新添加的情况下更改折线颜色,我找到了这个主题https://stackoverflow.com/questions/24226290/mkpoly
我正在使用 iOS 7 MapKit API 在显示 MKDirectionsRequest 生成的路径的 map 上生成 3D 相机移动。路径由 MKOverlayRenderer 渲染,如下所示:
我想根据速度等条件在多段线 View 上应用渐变。我能够子类化 MKPolyLineRenderer 以使用自定义描边和填充进行绘制,但只能沿路径使用相同的颜色。 我看到了其他类似的问题,例如:Dra
我认为 iOS 7 的 MKMapSnapshotter 将是拍摄 MKMapView 快照的简单方法,好处是您可以在不将 map 加载到 View 中的情况下执行此操作.尽管添加图钉和叠加层似乎需要
我是一名优秀的程序员,十分优秀!