Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. class ViewController: UIViewController {
  2. var circle : UIView!
  3. override func viewDidLoad() {
  4. super.viewDidLoad()
  5. // Do any additional setup after loading the view, typically from a nib.
  6. let animator = UIViewPropertyAnimator(duration: 10, curve: .easeInOut)
  7. circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0))
  8. circle.layer.cornerRadius = 20.0
  9. circle.backgroundColor = UIColor.blue
  10. self.view.addSubview(circle)
  11. Timer.scheduledTimer(withTimeInterval: 0.2, repeats: true)
  12. {
  13. [weak self] (myTimer) -> Void in
  14. if let movingBlueDotFrame = self?.circle.layer.presentation()?.frame
  15. {
  16. let blueDotOriginPoint = movingBlueDotFrame.origin
  17. let blueDotMiddlePoint = CGPoint(x: blueDotOriginPoint.x + movingBlueDotFrame.width/2, y: blueDotOriginPoint.y + movingBlueDotFrame.height/2)
  18. print(blueDotMiddlePoint)
  19. if blueDotMiddlePoint == CGPoint(x:100,y:100){
  20. print("Yeeaahh")
  21. myTimer.invalidate()
  22. }
  23. }
  24. }
  25. animator.addAnimations {
  26. self.circle.center = CGPoint(x: 100,y: 100)
  27. }
  28. animator.startAnimation()
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement