点击按钮,使按钮进行左右翻转动画

 1 // UIView.transition
 2 
 3 // 1、可以设置从一个View到另一个View的转场动画
 4 // UIView.transition(from: <#T##UIView#>, to: <#T##UIView#>, duration: <#T##TimeInterval#>, options: <#T##UIViewAnimationOptions#>, completion: <#T##((Bool) -> Void)?##((Bool) -> Void)?##(Bool) -> Void#>)
 5 
 6 // 2、可以设置一个View的动画(比如翻转)
 7 // UIView.transition(with: <#T##UIView#>, duration: <#T##TimeInterval#>, options: <#T##UIViewAnimationOptions#>, animations: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>, completion: <#T##((Bool) -> Void)?##((Bool) -> Void)?##(Bool) -> Void#>)
 8 
 9 import UIKit
10 
11 class ViewController: UIViewController {
12     
13     private var isZhengMian:Bool = true
14     
15     override func viewDidLoad() {
16         super.viewDidLoad()
17     }
18     
19     @IBAction func btnClick(_ sender: UIButton) {
20         isZhengMian = !isZhengMian
21         if isZhengMian{ // 正面,带文字,从左向右翻转
22             UIView.transition(with: sender, duration: 0.5, options: UIViewAnimationOptions.transitionFlipFromLeft, animations: {
23                 sender.setTitle("", for: .normal)
24             }, completion: { (_) in
25                 
26             })
27         } else{ // 反面,不带文字,从右向左翻转
28             UIView.transition(with: sender, duration: 0.5, options: UIViewAnimationOptions.transitionFlipFromRight, animations: {
29                 sender.setTitle(nil, for: .normal)
30             }, completion: { (_) in
31                 
32             })
33         }
34     }
35 }

 

posted @ 2017-01-03 18:30  小课桌  阅读(562)  评论(0编辑  收藏  举报