質問

I am using google map , and I have used GMS Map view.In map view I have created one GMS marker for current location and it is updating every one second with current latitude and longitude value.I used this code:

 mMapView = [[GMSMapView alloc]init];
    mMapView.delegate = self;
    mMapView.myLocationEnabled = YES;
 mMapView.frame = CGRectMake(0, 95, self.view.frame.size.width,self.view.frame.size.height -205);

GMSMarker *disMarker = [GMSMarker markerWithPosition:coordinateEndLocation];
        disMarker.snippet = @"current Location";

        disMarker.animated = YES;
        disMarker.map = mMapView;

But I want that this marker should be blinking in every second.Please tell me what I am doing wrong?

役に立ちましたか?

解決

CABasicAnimation *theAnimation;

theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=1.0;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.0];
[yourMarker.layer addAnimation:theAnimation forKey:@"animateOpacity"];

This is how to do a repeating fade in/out every second, except that the Google Maps iOS SDK (as of 1.8) won't obey the repeatCount or autoreverses properties. It fades, but never comes back.

他のヒント

Swift 5.0 Pass your GMSMarker object in blinkMarker method.

 func blinkMarker(marker: GMSMarker){
        let key = "blink"
        globalMarker = marker
        let pulseAnimation = CABasicAnimation(keyPath: "opacity")
        pulseAnimation.delegate = self
        pulseAnimation.fromValue = 1
        pulseAnimation.toValue = 0
        pulseAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        pulseAnimation.autoreverses = true
        globalMarker?.layer.add(pulseAnimation, forKey: key)
    }

 // CABasicAnimation Delegate method
    func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
        if let gMarker = globalMarker {
            blinkMarker(marker:gMarker)
        }
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top