Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. //: A UIKit based Playground for presenting user interface
  2.  
  3. import UIKit
  4. import PlaygroundSupport
  5.  
  6. class MyViewController : UIViewController {
  7. private let roundedView = UIView(frame: CGRect(x: 10, y: 10, width: 50, height: 50))
  8.  
  9. override func viewDidLoad() {
  10. super.viewDidLoad()
  11.  
  12. roundedView.layer.cornerRadius = 25
  13. roundedView.backgroundColor = .red
  14. view.addSubview(roundedView)
  15. }
  16.  
  17. override func viewDidAppear(_ animated: Bool) {
  18. super.viewDidAppear(animated)
  19.  
  20. animate()
  21. }
  22.  
  23. // private func animate() {
  24. // var animator = UIViewPropertyAnimator(duration: 2, curve: .easeInOut) {
  25. // self.changeRoundedView(x: 100, y: 200, width: 200, cornerRadius: 0)
  26. // }
  27. //
  28. // animator.addCompletion { _ in
  29. // animator = UIViewPropertyAnimator(duration: 2, curve: .easeInOut) {
  30. // self.changeRoundedView(x: 10, y: 10, width: 50, cornerRadius: 25)
  31. // }
  32. //
  33. // animator.startAnimation()
  34. // }
  35. //
  36. // animator.startAnimation()
  37. // }
  38.  
  39. private func animate() {
  40. UIView.animate(withDuration: 2, delay: 0, options: .autoreverse, animations: {
  41. self.changeRoundedView(x: 100, y: 200, width: 200, cornerRadius: 0)
  42. }, completion: { _ in
  43. self.changeRoundedView(x: 10, y: 10, width: 50, cornerRadius: 25)
  44. })
  45. }
  46.  
  47. private func changeRoundedView(x: CGFloat, y: CGFloat, width: CGFloat, cornerRadius: CGFloat) {
  48. self.roundedView.frame.origin.x = x
  49. self.roundedView.frame.origin.y = y
  50. self.roundedView.frame.size.width = width
  51. self.roundedView.layer.cornerRadius = cornerRadius
  52. }
  53. }
  54. // Present the view controller in the Live View window
  55. PlaygroundPage.current.liveView = MyViewController()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement