Created
April 30, 2015 15:08
-
-
Save erica/1cbe8ee7c1b6ea80ac0a to your computer and use it in GitHub Desktop.
Auto Closure
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
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