Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: A UIKit based Playground for presenting user interface
- import UIKit
- import PlaygroundSupport
- class MyViewController : UIViewController {
- private let roundedView = UIView(frame: CGRect(x: 10, y: 10, width: 50, height: 50))
- override func viewDidLoad() {
- super.viewDidLoad()
- roundedView.layer.cornerRadius = 25
- roundedView.backgroundColor = .red
- view.addSubview(roundedView)
- }
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- animate()
- }
- // private func animate() {
- // var animator = UIViewPropertyAnimator(duration: 2, curve: .easeInOut) {
- // self.changeRoundedView(x: 100, y: 200, width: 200, cornerRadius: 0)
- // }
- //
- // animator.addCompletion { _ in
- // animator = UIViewPropertyAnimator(duration: 2, curve: .easeInOut) {
- // self.changeRoundedView(x: 10, y: 10, width: 50, cornerRadius: 25)
- // }
- //
- // animator.startAnimation()
- // }
- //
- // animator.startAnimation()
- // }
- private func animate() {
- UIView.animate(withDuration: 2, delay: 0, options: .autoreverse, animations: {
- self.changeRoundedView(x: 100, y: 200, width: 200, cornerRadius: 0)
- }, completion: { _ in
- self.changeRoundedView(x: 10, y: 10, width: 50, cornerRadius: 25)
- })
- }
- private func changeRoundedView(x: CGFloat, y: CGFloat, width: CGFloat, cornerRadius: CGFloat) {
- self.roundedView.frame.origin.x = x
- self.roundedView.frame.origin.y = y
- self.roundedView.frame.size.width = width
- self.roundedView.layer.cornerRadius = cornerRadius
- }
- }
- // Present the view controller in the Live View window
- PlaygroundPage.current.liveView = MyViewController()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement