Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save edwardean/a880bd7d8a5b0d848bd45045b130949a to your computer and use it in GitHub Desktop.
Save edwardean/a880bd7d8a5b0d848bd45045b130949a to your computer and use it in GitHub Desktop.
监听UISwitch动画结束
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