簡體   English   中英

UIView.animateWithDuration swift 3

[英]UIView.animateWithDuration swift 3

在此輸入圖像描述

按下按鈕時可以正常工作。 單擊此功能后顯示另一個視圖

@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)
    })
}

//按鍵動畫顯示...(適用於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)
    })

結果:


碼:

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
        })
      }
    }

  }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM