Ios 贴图视图动画上的覆盖
我添加了一个覆盖(多个坐标的数组)并绘制了一条路径 它工作得非常完美,但我希望(如果可能的话)用动画(逐坐标或淡入等)绘制路径 我的应用程序仅在iOS 7或更高版本上运行 以下是我的方法:Ios 贴图视图动画上的覆盖,ios,iphone,mkmapview,overlay,mkoverlay,Ios,Iphone,Mkmapview,Overlay,Mkoverlay,我添加了一个覆盖(多个坐标的数组)并绘制了一条路径 它工作得非常完美,但我希望(如果可能的话)用动画(逐坐标或淡入等)绘制路径 我的应用程序仅在iOS 7或更高版本上运行 以下是我的方法: - (void)drawPathWithAnnotations:(NSArray*)annotations { CLLocationCoordinate2D array[[annotations count]]; for (CLLocation *loc in annotations)
- (void)drawPathWithAnnotations:(NSArray*)annotations
{
CLLocationCoordinate2D array[[annotations count]];
for (CLLocation *loc in annotations)
{
array[[annotations indexOfObject:loc]] = CLLocationCoordinate2DMake(loc.coordinate.latitude, loc.coordinate.longitude);
}
self.routeLine = [MKPolyline polylineWithCoordinates:array count:[annotations count]];
[self.mapview addOverlay:self.routeLine];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if(overlay == self.routeLine){
MKPolylineRenderer* lineView = [[MKPolylineRenderer alloc] initWithPolyline:self.routeLine];
lineView.strokeColor = UIColorFromRGB(kAppTintColor);
lineView.lineWidth = 3;
return lineView;
}
return nil;
}
- (void)mapView:(MKMapView *)mapView didAddOverlayRenderers:(NSArray *)renderers
{
// Animation here ?
}
-(void)drawPathWithAnnotations:(NSArray*)注释
{
CLLocationCoordinate2D数组[[annotations count]];
用于(注释中的CLLocation*loc)
{
数组[[annotations indexOfObject:loc]]=CLLocationCoordinate2DMake(loc.coordinate.latitude,loc.coordinate.longitude);
}
self.routeLine=[MKPolyline polylineWithCoordinates:array count:[annotations count]];
[self.mapview addOverlay:self.routeLine];
}
-(MKOverlayRenderer*)地图视图:(MKMapView*)地图视图渲染器ForOverlay:(id)overlay
{
if(叠加==自布线){
MKPolylineRenderer*lineView=[[MKPolylineRenderer alloc]initWithPolyline:self.routeLine];
lineView.strokeColor=UIColorFromRGB(kAppTintColor);
lineView.lineWidth=3;
返回线视图;
}
返回零;
}
-(void)mapView:(MKMapView*)mapView DidAddOverlayRenders:(NSArray*)渲染器
{
//这里有动画吗?
}
谢谢,任何建议或想法都将不胜感激!:) 我一直在寻找你问题的答案,但没有找到一个被接受的答案,所以这里是我的解决方案。假设DidAddOverlayRenders是放置动画的地方,这是正确的。下面是如何为覆盖设置“淡入”动画的示例:
- (void)mapView:(MKMapView *)mapView didAddOverlayRenderers:(NSArray *)renderers
{
// Iterate through all overlayRenderers
for (MKOverlayRenderer *overlayRenderer in renderers)
{
// MKPolylineRenderer
// Animate a 'fade'
if ([overlayRenderer isKindOfClass:[MKPolylineRenderer class]])
{
// Get MKPolylineRenderer
MKPolylineRenderer *polylineRenderer = (MKPolylineRenderer *)overlayRenderer;
// Let's manually set alpha to 0
polylineRenderer.alpha = 0.0f;
// Animate it back to 1
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.4 animations:^{
polylineRenderer.alpha = 1.0f
}];
});
}
}
}
我认为这在MKPolylineRenderer身上是不可能的。您可以将路径作为单独的覆盖添加到计时器上,也可以添加一个覆盖,但可以创建一个自定义的MKOverlayPathRenderer,它在计时器上更新自己的
路径(从覆盖中添加下一个“步骤”),并在自身上调用invalidatePath以刷新显示。在这两种情况下,重叠仍然是MKPolyline对象。好的,明白了;)。如果有人尝试了这个解决方案,我会在这里更新我的帖子。谢谢你的解释;)@拉皮努你好,我还需要解决这个问题。你这样做了吗。请让我知道。谢谢@开发者你好!不,我没有找到解决方案:/@Lapinou-Thn试试这个:它对我有用。