Skip to content

Instantly share code, notes, and snippets.

@samhenrigold
Last active April 19, 2025 22:35
Show Gist options
  • Save samhenrigold/5b88f12283513d8808d8cc9b65bc47ee to your computer and use it in GitHub Desktop.
Save samhenrigold/5b88f12283513d8808d8cc9b65bc47ee to your computer and use it in GitHub Desktop.
`UIView.SystemAnimation.delete` demo playground
/// Video demo: https://hachyderm.io/@samhenrigold/114359529882977822
import UIKit
import PlaygroundSupport
final class DeleteDemoVC: UIViewController {
private let stack = UIStackView()
override func viewDidLoad() {
super.viewDidLoad()
stack.axis = .vertical
stack.spacing = 12
stack.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stack)
NSLayoutConstraint.activate([
stack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
stack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
stack.widthAnchor.constraint(equalToConstant: 200)
])
(1...5).forEach {
stack.addArrangedSubview(makeRow("Row \($0)"))
}
}
private func makeRow(_ title: String) -> UIButton {
let button = UIButton(type: .system)
var config = UIButton.Configuration.filled()
config.title = title
config.buttonSize = .large
config.titleTextAttributesTransformer = .init({ incoming in
var outgoing = incoming
outgoing.font = .boldSystemFont(ofSize: 24)
return outgoing
})
button.configuration = config
button.addAction(UIAction { [weak self] _ in
guard let self else { return }
UIView.perform(.delete, on: [button], options: [], animations: nil) { _ in
UIView.animate { self.stack.layoutIfNeeded() }
}
}, for: .touchUpInside)
return button
}
}
PlaygroundPage.current.liveView = DeleteDemoVC()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment