Skip to content

Instantly share code, notes, and snippets.

@junpluse
Last active April 27, 2016 11:27
Show Gist options
  • Save junpluse/956c4822d36f584ba31ea2299cb50cc7 to your computer and use it in GitHub Desktop.
Save junpluse/956c4822d36f584ba31ea2299cb50cc7 to your computer and use it in GitHub Desktop.
UIView subclass for Core Animation lovers
import UIKit
final class LayerView<Layer: CALayer>: UIView {
var implicitAnimationsEnabled: Bool = false
var implicitlyAnimatableEvents: [String]? = nil
var genericLayer: Layer {
return layer as! Layer
}
init(frame: CGRect = CGRect.zero, configuration: ((Layer) -> Void)? = nil) {
super.init(frame: frame)
configuration?(genericLayer)
}
override class func layerClass() -> AnyClass {
return Layer.self
}
override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
if implicitAnimationsEnabled {
if implicitlyAnimatableEvents == nil || implicitlyAnimatableEvents!.contains(event) {
return nil
}
}
return super.actionForLayer(layer, forKey: event)
}
func update(@noescape closure: (Layer) -> Void) {
closure(genericLayer)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment