5

enter image description here

When the button is pressed it works. After clicking this function shows another view

@IBAction func charSetPressed(_ button: UIButton) {
    if button.titleLabel!.text == "1/2" {

        charSet1.isHidden = true
        charSet2.isHidden = false

        button.setTitle("2/2", for: .normal)

    } else if button.titleLabel!.text == "2/2" {
        charSet1.isHidden = false
        charSet2.isHidden = true
        button.setTitle("1/2", for: .normal)
    }

    UIView.animateWithDuration(0.2, animations: {

        button.transform = CGAffineTransformScale(CGAffineTransformIdentity, 2.0, 2.0)
        }, completion: {(_) -> Void in(here the error happend)

            button.transform =
            CGAffineTransformScale(CGAffineTransformIdentity, 1, 1)
    })
}
ArK
  • 20,698
  • 67
  • 109
  • 136

2 Answers2

7

//Animate on key press... (For Swift 3.0)

    UIView.animate(withDuration: 0.2, animations: {
        button.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
    }, completion:{ _ in
        button.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
    })
Sandip Patel - SM
  • 3,346
  • 29
  • 27
4

Result:


Code:

import UIKit
import Foundation

class ViewController: UIViewController {
  
  @IBOutlet weak var myView: UIView!
  
  @IBAction func buttonTouched(_ sender: AnyObject) {
    
    // animate scaling by 2.0, 2.0
    UIView.animate(withDuration: 0.2, animations: {
      let transformScaled = CGAffineTransform
                                          .identity
                                          .scaledBy(x: 2.0, y: 2.0)

      self.myView.transform = transformScaled
    }) { (finished) in
      // once finished first animation
      // start second animation
      if finished {
        // animate scaling by 1.0, 1.0
        UIView.animate(withDuration: 0.2, animations: { 
          let transformScaled = CGAffineTransform
                                              .identity
                                              .scaledBy(x: 1.0, y: 1.0)
          
          self.myView.transform = transformScaled
        })
      }
    }
    
  }
  
}
Community
  • 1
  • 1
Wilson
  • 9,006
  • 3
  • 42
  • 46