Litle Dev
Litle Dev

Reputation: 493

How to remove google map marker with fade out animation iOS swift 3?

I am trying to remove my google map marker with fade out animation. And I have tried

CATransaction.begin()
CATransaction.setAnimationDuration(1.0)
myMarker.marker?.map = nil
CATransaction.commit()

CATransaction worked for myMarker.marker?.rotation but not working for fade out animation. What should I do now?

Upvotes: 1

Views: 961

Answers (2)

Litle Dev
Litle Dev

Reputation: 493

When there are several markers or some code snippet depend on that marker, and you need to remove them synchronously then the process you should be done in background thread. But the background thread can't update the UI.

So, the UI update portion you need do in main thread. Like I have done here,

//Swift 3.1
DispatchQueue.global(qos: .background).async {

    //HERE MAY HAVE SOME DEPENDENT CODE

    DispatchQueue.main.async {
        UIView.animate(withDuration: 0.5, animations: {
            self.myMarker.marker?.opacity = 0.0
        }, completion: { (yes) in
            self.myMarker.marker?.map = nil
        })
    }

    //HERE MAY HAVE SOME DEPENDENT CODE

}

Upvotes: 2

NeverHopeless
NeverHopeless

Reputation: 11233

Try like this to hide it with animation, use any method of your choice in option parameter:

UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseOut, animations: { 

      self.myMarker.opacity = 0.0

}, completion: { (true) in

      self.myMarker.map = nil              
})

Upvotes: 2

Related Questions