Last active
April 27, 2016 11:27
-
-
Save junpluse/956c4822d36f584ba31ea2299cb50cc7 to your computer and use it in GitHub Desktop.
UIView subclass for Core Animation lovers
This file contains hidden or 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 | |
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