Last active
July 30, 2019 10:31
-
-
Save dcramps/a67eb0aa8eacba4da283130152ef0cc6 to your computer and use it in GitHub Desktop.
Animation stuff
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
| import UIKit | |
| class AnimationThing: UIViewController { | |
| let toolbar = UIView() | |
| let doAThing = Notification.Name(rawValue: "DoAThing") | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| setUpViews() | |
| NotificationCenter.default.addObserver( | |
| self, | |
| selector: #selector(notified), | |
| name: doAThing, | |
| object: nil) | |
| } | |
| private func setUpViews() { | |
| let tap = UITapGestureRecognizer(target: self, action: #selector(sendNotification)) | |
| view.isUserInteractionEnabled = true | |
| view.addGestureRecognizer(tap) | |
| view.backgroundColor = .white | |
| toolbar.backgroundColor = .black | |
| toolbar.translatesAutoresizingMaskIntoConstraints = false | |
| view.addSubview(toolbar) | |
| NSLayoutConstraint.activate([ | |
| toolbar.leadingAnchor.constraint(equalTo: view.leadingAnchor), | |
| toolbar.trailingAnchor.constraint(equalTo: view.trailingAnchor), | |
| toolbar.centerYAnchor.constraint(equalTo: view.centerYAnchor), | |
| toolbar.heightAnchor.constraint(equalToConstant: 88), | |
| ]) | |
| } | |
| @objc private func sendNotification() { | |
| UIView.animate(withDuration: 0.25) { | |
| NotificationCenter.default.post(name: self.doAThing, object: nil) | |
| } | |
| } | |
| @objc private func notified(n: NSNotification) { | |
| toolbar.transform = toolbar.transform.translatedBy(x: 0.0, y: CGFloat.random(in: -100..<100)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment