2016-02-23 4 views
0

Мне нужно мигать или анимировать маркер на картах google. Я пробовал использовать CALayer, но он просто моргнул один раз. Код «pulseAnimation.repeatCount = FLT_MAX» не работает. Он мигает только один раз. Есть ли способ решить мою проблему ??Изображение маркера на картах google blink

func loadMap(){ 
     let camera = GMSCameraPosition.cameraWithLatitude(-33.86, 
      longitude: 151.20, zoom: 15) 
     let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera) 
     mapView.myLocationEnabled = true 

    // change map type 
    mapView.mapType = kGMSTypeNormal 

    self.view = mapView 

    let marker = GMSMarker() 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20) 

    //custom marker 
    marker.appearAnimation = kGMSMarkerAnimationPop 
    marker.icon = UIImage(named: "maprymarker") 
    marker.title = "Sydney" 
    marker.snippet = "Australia" 
    marker.map = mapView 
    let pulseAnimation = CABasicAnimation(keyPath: "opacity") 
    pulseAnimation.duration = 1 
    pulseAnimation.fromValue = 0 
    pulseAnimation.toValue = 1 
    pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 
    pulseAnimation.autoreverses = true 
    pulseAnimation.repeatCount = FLT_MAX 
    marker.layer.addAnimation(pulseAnimation, forKey: nil) 

} 
+0

Знайте, что знаете ответ – Sree

ответ

1

Добавить методы делегирования анимации, а затем снова вызвать ту же функцию.

func blink(){ 
    var i:Int = 0 
    for marker in markerBlink{ 
     let pulseAnimation = CABasicAnimation(keyPath: "opacity") 
     pulseAnimation.delegate = self 
     pulseAnimation.duration = 1.0 
     pulseAnimation.fromValue = 1 
     pulseAnimation.toValue = 0 
     pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 
     pulseAnimation.autoreverses = true 
     marker.layer.addAnimation(pulseAnimation, forKey: "\(++i)") 
    } 

} 

override func animationDidStop(anim: CAAnimation, finished flag: Bool) { 
    if flag{ 

     blink() 

    } 
} 
Смежные вопросы