Created
May 3, 2020 08:01
-
-
Save Josscii/ef13409a5e41aba31b0243c762790567 to your computer and use it in GitHub Desktop.
去掉 CALayer 的隐式动画
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
//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