标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import UIKit class ViewController : UIViewController { //游戏方格维度 var dimension: Int = 4 //数字格子的宽度 var width: CGFloat = 50 //格子与格子的间距 var padding: CGFloat = 6 //保存背景图数据 var backgrounds: Array < UIView >! override func viewDidLoad() { super .viewDidLoad() self .backgrounds = Array < UIView >() setupGameMap() playAnimation() } func setupGameMap() { var x: CGFloat = 50 var y: CGFloat = 150 for i in 0..<dimension { println (i) y = 150 for j in 0..<dimension { //初始化视图 var background = UIView (frame: CGRectMake (x, y, width, width)) background.backgroundColor = UIColor .darkGrayColor() self .view.addSubview(background) //将视图保存起来,以备后用 backgrounds.append(background) y += padding + width } x += padding+width } } func playAnimation() { for tile in backgrounds{ //先将数字块大小置为原始尺寸的 1/10 tile.layer.setAffineTransform( CGAffineTransformMakeScale (0.1,0.1)) //设置动画效果,动画时间长度 1 秒。 UIView .animateWithDuration(1, delay:0.01, options: UIViewAnimationOptions . TransitionNone , animations: { ()-> Void in //在动画中,数字块有一个角度的旋转。 tile.layer.setAffineTransform( CGAffineTransformMakeRotation (90)) }, completion:{ (finished: Bool ) -> Void in UIView .animateWithDuration(1, animations:{ ()-> Void in //完成动画时,数字块复原 tile.layer.setAffineTransform( CGAffineTransformIdentity ) }) }) } } override func didReceiveMemoryWarning() { super .didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
func playAnimation() { for tile in backgrounds{ //先将数字块大小置为原始尺寸的 1/10 tile.layer.setAffineTransform( CGAffineTransformMakeScale (0.1,0.1)) //设置动画效果,动画时间长度 1 秒。 UIView .animateWithDuration(1, delay:0.01, options: UIViewAnimationOptions . TransitionNone , animations: { ()-> Void in tile.layer.setAffineTransform( CGAffineTransformMakeScale (1,1)) }, completion:{ (finished: Bool ) -> Void in UIView .animateWithDuration(0.08, animations:{ ()-> Void in tile.layer.setAffineTransform( CGAffineTransformIdentity ) }) }) } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
func playAnimation() { for tile in backgrounds{ tile.alpha = 0; //设置动画效果,动画时间长度 1 秒。 UIView .animateWithDuration(1, delay:0.01, options: UIViewAnimationOptions . CurveEaseInOut , animations: { ()-> Void in }, completion:{ (finished: Bool ) -> Void in UIView .animateWithDuration(1, animations:{ ()-> Void in tile.alpha = 1 }) }) } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
//淡出动画 UIView .beginAnimations( nil , context: nil ) UIView .setAnimationDuration(2.0) imageView.alpha = 0.0 UIView .commitAnimations() //淡入动画 UIView .beginAnimations( nil , context: nil ) UIView .setAnimationDuration(2.0) imageView.alpha = 1.0 UIView .commitAnimations() //移动动画 UIView .beginAnimations( nil , context: nil ) UIView .setAnimationDuration(2.0) imageView.center = CGPointMake (250, 250) UIView .setAnimationCurve( UIViewAnimationCurve . EaseOut ) //设置动画相对速度 UIView .commitAnimations() //大小调整动画 UIView .beginAnimations( nil , context: nil ) UIView .setAnimationDuration(2.0) imageView.frame = CGRectMake (100,180,50,50) UIView .commitAnimations() |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
var redView: UIView = UIView (frame: CGRectMake (50,50,150,400)) redView.backgroundColor = UIColor .redColor() self .view.insertSubview(redView, atIndex: 0) var blueView: UIView = UIView (frame: CGRectMake (50,50,150,400)) blueView.backgroundColor = UIColor .blueColor() self .view.insertSubview(blueView, atIndex: 1) UIView .beginAnimations( nil , context: nil ) UIView .setAnimationDuration(4.0) UIView .setAnimationTransition( UIViewAnimationTransition . CurlUp , forView: self .view, cache: true ) self .view.exchangeSubviewAtIndex(1, withSubviewAtIndex: 0) UIView .commitAnimations() |
1
2
3
4
5
6
|
//将整个主视图面板实现一个翻转效果 UIView .beginAnimations( "animation" , context: nil ) UIView .setAnimationDuration(2) UIView .setAnimationCurve( UIViewAnimationCurve . EaseInOut ) UIView .setAnimationTransition( UIViewAnimationTransition . FlipFromLeft , forView: self .view, cache: false ) UIView .commitAnimations() |
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4838401.html