Iphone iOS 6-地图视图,叠加淡入
我一直在开发一个应用程序,它可以画出当前用户在地图上移动的路线。现在,在iOS5中,当我将覆盖添加到mapview时,它只需直接添加,在iOS6中,它使用淡入动画添加覆盖。我不想要这个讨厌的动画。我还有一个功能,在用户完成跑步或步行后,根据保存的坐标播放轨迹,当我播放时,线条闪烁得非常快,正是因为这个动画。这真的很烦人,我真的很感激任何指导或解决方案来摆脱这个动画 用于添加覆盖的代码:Iphone iOS 6-地图视图,叠加淡入,iphone,ios,ios5,ios6,overlay,Iphone,Ios,Ios5,Ios6,Overlay,我一直在开发一个应用程序,它可以画出当前用户在地图上移动的路线。现在,在iOS5中,当我将覆盖添加到mapview时,它只需直接添加,在iOS6中,它使用淡入动画添加覆盖。我不想要这个讨厌的动画。我还有一个功能,在用户完成跑步或步行后,根据保存的坐标播放轨迹,当我播放时,线条闪烁得非常快,正是因为这个动画。这真的很烦人,我真的很感激任何指导或解决方案来摆脱这个动画 用于添加覆盖的代码: MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoord
MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoordinate2D)*2);
pointsArray[0]= MKMapPointForCoordinate(oldLocation.coordinate);
pointsArray[1]= MKMapPointForCoordinate(newLocation.coordinate);
self.routeLine = [MKPolyline polylineWithPoints:pointsArray count:2];
free(pointsArray);
[self.mapView addOverlay:self.routeLine];
显示覆盖的代码:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay{
MKOverlayView *overlayView = nil;
MKPolylineView *routeLineView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];
routeLineView.fillColor = [UIColor blueColor];
routeLineView.strokeColor = [UIColor blueColor];
routeLineView.backgroundColor = [UIColor clearColor];
routeLineView.lineWidth = 10;
routeLineView.lineCap = kCGLineCapRound;
overlayView = routeLineView;
return overlayView;
}
不使用MKPolylineView,您可以使用MKPolylineView的MKOverlayView超类的自己的子类,然后覆盖drawMapRect:zoomScale:inContext:在其中自己绘制直线 我想你不会有任何淡入动画我使用它,从来没有注意到任何动画 请为drawMapRect:zoomScale:inContext:implementation尝试以下代码。 您需要创建lineColorCGColor和lineWidth CGFloat属性
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
MKPolyline *polyline = self.overlay;
CGContextSetStrokeColorWithColor(context, self.lineColor);
CGContextSetLineWidth(context, self.lineWidth/zoomScale);
CGMutablePathRef path = CGPathCreateMutable();
CGPoint *points = malloc(sizeof(CGPoint)*polyline.pointCount);
for (int i=0; i<polyline.pointCount; i++) {
points[i] = [self pointForMapPoint:polyline.points[i]];
}
CGPathAddLines(path, NULL, points, polyline.pointCount);
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(path);
free(points);
}
这只发生在模拟器或设备中吗?我有类似的东西,我看不到主要的闪烁。它只发生在设备上,而不是模拟器上。我会查看它,但也会显示你通过路径使用的代码。这可能与此有关。添加了通过路径的代码,没有任何异常!我仍在查看代码,但不需要将计时器添加到运行循环中。NSTimer scheduledTimerWithTimeInterval:已执行此操作。如果计时器触发两次,这可能是相关的。我将评论进一步的发现。然后我需要子类MKMapView?不。您需要子类MKOverlayView,而不是使用MKPolylineView,而是使用新的子类。为了让答案更清楚,我将重新措辞。你能给我一个关于重写方法的例子吗?添加了示例代码。试试看,让我知道它是如何工作的。我无法测试它,所以如果您发现某些东西不起作用,请告诉我。问题仍然存在,与添加覆盖层无关。我甚至用苹果面包屑来达到这个效果,但它也不起作用。这是iOS 6:s中的一个bug
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
MKPolyline *polyline = self.overlay;
CGContextSetStrokeColorWithColor(context, self.lineColor);
CGContextSetLineWidth(context, self.lineWidth/zoomScale);
CGMutablePathRef path = CGPathCreateMutable();
CGPoint *points = malloc(sizeof(CGPoint)*polyline.pointCount);
for (int i=0; i<polyline.pointCount; i++) {
points[i] = [self pointForMapPoint:polyline.points[i]];
}
CGPathAddLines(path, NULL, points, polyline.pointCount);
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(path);
free(points);
}