Skip to content

Instantly share code, notes, and snippets.

@Josscii
Created May 3, 2020 08:01
Show Gist options
  • Save Josscii/ef13409a5e41aba31b0243c762790567 to your computer and use it in GitHub Desktop.
Save Josscii/ef13409a5e41aba31b0243c762790567 to your computer and use it in GitHub Desktop.
去掉 CALayer 的隐式动画
//https://stackoverflow.com/a/58518282/4819236
extension CALayer {
var areAnimationsEnabled: Bool {
get { delegate == nil }
set { delegate = newValue ? nil : CALayerAnimationsDisablingDelegate.shared }
}
}
private class CALayerAnimationsDisablingDelegate: NSObject, CALayerDelegate {
static let shared = CALayerAnimationsDisablingDelegate()
private let null = NSNull()
func action(for layer: CALayer, forKey event: String) -> CAAction? {
null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment