Skip to content

Instantly share code, notes, and snippets.

@ziyang0621
Created June 30, 2015 21:22
Show Gist options
  • Save ziyang0621/c8ee4b9981d1eb1343ff to your computer and use it in GitHub Desktop.
Save ziyang0621/c8ee4b9981d1eb1343ff to your computer and use it in GitHub Desktop.
func delay(#seconds: Double, completion:()->()) {
let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64( Double(NSEC_PER_SEC) * seconds ))
dispatch_after(popTime, dispatch_get_main_queue()) {
completion()
}
}
class ViewController: UIViewController, GMSMapViewDelegate {
var mapView: GMSMapView?
var percent: CGFloat = 1.0
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.whiteColor();
let camera = GMSCameraPosition.cameraWithLatitude(-37.813047, longitude: -72.8561644, zoom:7)
mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)
let marker = GMSMarker()
marker.position = camera.target
marker.snippet = "Hello World"
marker.appearAnimation = kGMSMarkerAnimationPop
marker.map = mapView
let originalImage = UIImage(named: "markerIcon")
let newImage = originalImage
marker.icon = newImage
self.view = mapView
self.mapView?.delegate = self
}
func newImageWithWidth(image: UIImage, width: CGFloat, height: CGFloat) -> UIImage{
let imageSize = CGSize(width: width, height: height)
UIGraphicsBeginImageContext(imageSize)
let imageRect = CGRectMake(0, 0, width, height)
image.drawInRect(imageRect)
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return resizedImage
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {
let originalImage = UIImage(named: "markerIcon")
delay(seconds: 0.05) { () -> () in
marker.icon = self.newImageWithWidth(originalImage!, width: originalImage!.size.width/2, height: originalImage!.size.height)
delay(seconds: 0.05, { () -> () in
marker.icon = self.newImageWithWidth(originalImage!, width: 0.1, height: originalImage!.size.height)
delay(seconds: 0.05, { () -> () in
marker.icon = self.newImageWithWidth(originalImage!, width: originalImage!.size.width/2, height: originalImage!.size.height)
delay(seconds: 0.05, { () -> () in
marker.icon = self.newImageWithWidth(originalImage!, width: originalImage!.size.width, height: originalImage!.size.height)
})
})
})
}
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment