Advertisement
Guest User

buttonspring

a guest
Oct 7th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // DemoApp
  4. //
  5. // Created by Chris on 01/10/2015.
  6. // Copyright © 2015 Chris. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.  
  13. @IBOutlet weak var aButton: UIButton!
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do any additional setup after loading the view, typically from a nib.
  17. }
  18.  
  19.  
  20. @IBAction func clickFunction(sender: UIView) {
  21.  
  22. animateButton(sender, step: 2)
  23.  
  24. }
  25.  
  26.  
  27. func animateButton(aButton: UIView ,step: Int)
  28. {
  29. let origin:CGFloat = 101
  30. let newY = aButton.frame.origin.y - aButton.frame.size.height * 0.2
  31. let newYa = aButton.frame.origin.y - aButton.frame.size.height * 0.25// Here we are figuring out what the new y-position should be
  32. let newYab = aButton.frame.origin.y - aButton.frame.size.height
  33.  
  34. var transform: CGAffineTransform
  35. if(aButton.frame.size.height > 75){
  36. UIView.animateWithDuration(0.4, animations: { () -> Void in
  37. aButton.transform = CGAffineTransformMakeScale(1, 1.2)
  38. aButton.frame.origin = CGPointMake(aButton.frame.origin.x, newY) // Here we are changing the button's origin to our newly calculated y-position
  39. }, completion:
  40. {
  41. (finished) in
  42. UIView.animateWithDuration(0.4, animations: { () -> Void in
  43. aButton.transform = CGAffineTransformMakeScale(1, 0.25)
  44. aButton.frame.origin = CGPointMake(aButton.frame.origin.x, origin + newYa) // Here we are changing the button's origin to our newly calculated y-position
  45.  
  46.  
  47. })
  48. }
  49. )
  50. }else{
  51. UIView.animateWithDuration(0.4, animations: { () -> Void in
  52. aButton.transform = CGAffineTransformMakeScale(1, 0.1)
  53. aButton.frame.origin = CGPointMake(aButton.frame.origin.x, origin + newYab) // Here we are changing the button's origin to our newly calculated y-position
  54. }, completion:
  55. {
  56. (finished) in
  57. UIView.animateWithDuration(0.4, animations: { () -> Void in
  58. // aButton.transform = CGAffineTransformMakeScale(1, 0.25)
  59. // aButton.frame.origin = CGPointMake(aButton.frame.origin.x, origin + newYa) // Here we are changing the button's origin to our newly calculated y-position
  60. })
  61. }
  62. )
  63.  
  64. }
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71. override func didReceiveMemoryWarning() {
  72. super.didReceiveMemoryWarning()
  73. // Dispose of any resources that can be recreated.
  74. }
  75.  
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement