如何在iOS的GoogleMap上用动画绘制和删除折线?

时间:2019-02-27 07:26:04

标签: ios objective-c google-maps google-polyline ios-animations

我想在GoogleMap上绘制带有动画的折线,就像Uber一样。目前,我可以在绘制时进行动画处理(不像Uber那样平滑),但是在移除时没有平滑性。

如何实现以下目标?

  1. 绘制多段线的持续时间应该与路径的长度相同。
  2. 在删除折线时,我要使用淡出动画来实现。

这是相关的代码。

@property(nonatomic, strong) GMSPath *poolRidePath;
@property (nonatomic,assign) int counter;
@property (nonatomic,strong) GMSMutablePath *trackPath;
@property (nonatomic,strong) GMSPolyline *yellowPolyLine;
@property (nonatomic,strong) NSMutableArray *arrayPolylineYellow;
@property (nonatomic,strong) GMSMapView *mapView;

.....
.....
.....


double time = 0.8/self.poolRidePath.count;

self.timerForPathProgressAnimation = [NSTimer scheduledTimerWithTimeInterval: time repeats:true block:^(NSTimer * _Nonnull timer) {
                                [self animateMapRouteLine: self.poolRidePath];
                            }];
.....
.....
.....

-(void)animateMapRouteLine:(GMSPath *)path {

  if (self.counter < path.count) {

    [self.trackPath addCoordinate:[path coordinateAtIndex: self.counter]];

    self.yellowPolyLine = [GMSPolyline polylineWithPath: self.trackPath];
    self.yellowPolyLine.strokeColor = [[CommonFunctions shareCommonMethods] colorFromHexString:@"#e6b800"];
    self.yellowPolyLine.strokeWidth = 3;
    self.yellowPolyLine.map = self.mapView;
    [self.arrayPolylineYellow addObject: self.yellowPolyLine];
    self.counter++;
 } else {
     self.counter = 0;
     self.trackPath = [[GMSMutablePath alloc] init];
     for (GMSPolyline *line in self.arrayPolylineYellow) {
        line.map = nil;
     } 
   }
}

0 个答案:

没有答案