Created
May 28, 2018 10:33
-
-
Save edwardean/a880bd7d8a5b0d848bd45045b130949a to your computer and use it in GitHub Desktop.
监听UISwitch动画结束
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
addTarget(self, action: #selector(valueChanged(sender:)), for: [.valueChanged]) | |
@objc private func valueChanged(sender: UISwitch) { | |
CATransaction.setCompletionBlock { [onChange] in | |
onChange?(sender.isOn) | |
} | |
} | |
The documentation says the block is guaranteed to be called even if there are no animations or the animation was removed. It makes it very safe to use. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment