Created
June 30, 2015 21:22
-
-
Save ziyang0621/c8ee4b9981d1eb1343ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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