Skip to content

Instantly share code, notes, and snippets.

@erica
Created April 30, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erica/1cbe8ee7c1b6ea80ac0a to your computer and use it in GitHub Desktop.
Save erica/1cbe8ee7c1b6ea80ac0a to your computer and use it in GitHub Desktop.
Auto Closure
import UIKit
import XCPlayground
// Please enable simulator to view results in playground
extension UIView {
class func animate(duration : NSTimeInterval, @autoclosure _ animations : () -> Void) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(duration)
animations()
UIView.commitAnimations()
}
}
let view = UIView(frame:CGRectMake(0, 0, 200, 180))
view.backgroundColor = .redColor()
XCPShowView("View", view)
UIView.animate(2.0, view.backgroundColor = .blueColor())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment