Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // DemoApp
- //
- // Created by Chris on 01/10/2015.
- // Copyright © 2015 Chris. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var aButton: UIButton!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- @IBAction func clickFunction(sender: UIView) {
- animateButton(sender, step: 2)
- }
- func animateButton(aButton: UIView ,step: Int)
- {
- let origin:CGFloat = 101
- let newY = aButton.frame.origin.y - aButton.frame.size.height * 0.2
- let newYa = aButton.frame.origin.y - aButton.frame.size.height * 0.25// Here we are figuring out what the new y-position should be
- let newYab = aButton.frame.origin.y - aButton.frame.size.height
- var transform: CGAffineTransform
- if(aButton.frame.size.height > 75){
- UIView.animateWithDuration(0.4, animations: { () -> Void in
- aButton.transform = CGAffineTransformMakeScale(1, 1.2)
- aButton.frame.origin = CGPointMake(aButton.frame.origin.x, newY) // Here we are changing the button's origin to our newly calculated y-position
- }, completion:
- {
- (finished) in
- UIView.animateWithDuration(0.4, animations: { () -> Void in
- aButton.transform = CGAffineTransformMakeScale(1, 0.25)
- aButton.frame.origin = CGPointMake(aButton.frame.origin.x, origin + newYa) // Here we are changing the button's origin to our newly calculated y-position
- })
- }
- )
- }else{
- UIView.animateWithDuration(0.4, animations: { () -> Void in
- aButton.transform = CGAffineTransformMakeScale(1, 0.1)
- aButton.frame.origin = CGPointMake(aButton.frame.origin.x, origin + newYab) // Here we are changing the button's origin to our newly calculated y-position
- }, completion:
- {
- (finished) in
- UIView.animateWithDuration(0.4, animations: { () -> Void in
- // aButton.transform = CGAffineTransformMakeScale(1, 0.25)
- // aButton.frame.origin = CGPointMake(aButton.frame.origin.x, origin + newYa) // Here we are changing the button's origin to our newly calculated y-position
- })
- }
- )
- }
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement