문제

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