简体   繁体   中英

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?

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              
})

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM