Swift - 啓動畫面放大淡出效果的實現1(使用launch image)
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
|
import UIKit class ViewController : UIViewController { override func viewDidLoad()
{ super .viewDidLoad() //播放啓動畫面動畫 launchAnimation() } //播放啓動畫面動畫 private func launchAnimation()
{ let statusBarOrientation
= UIApplication .sharedApplication().statusBarOrientation if let img
= splashImageForOrientation(statusBarOrientation, size: self .view.bounds.size)
{ //獲取啓動圖片 let launchImage
= UIImage (named:
img) let launchview
= UIImageView (frame: UIScreen .mainScreen().bounds) launchview.image
= launchImage //將圖片添加到視圖上 //self.view.addSubview(launchview) let delegate
= UIApplication .sharedApplication().delegate let mainWindow
= delegate?.window mainWindow!!.addSubview(launchview) //播放動畫效果,完畢後將其移除 UIView .animateWithDuration(1,
delay: 1.5, options: . BeginFromCurrentState , animations:
{ launchview.alpha
= 0.0 launchview.layer.transform
= CATransform3DScale ( CATransform3DIdentity ,
1.5, 1.5, 1.0) })
{ (finished) in launchview.removeFromSuperview() } } } //獲取啓動圖片名(根據設備方向和尺寸) func splashImageForOrientation(orientation: UIInterfaceOrientation ,
size: CGSize )
-> String ?{ //獲取設備尺寸和方向 var viewSize
= size var viewOrientation
= "Portrait" if UIInterfaceOrientationIsLandscape (orientation)
{ viewSize
= CGSizeMake (size.height,
size.width) viewOrientation
= "Landscape" } //遍歷資源庫中的所有啓動圖片,找出符合條件的 if let imagesDict
= NSBundle .mainBundle().infoDictionary
{ if let imagesArray
= imagesDict[ "UILaunchImages" ] as ?
[[ String : String ]]
{ for dict in imagesArray
{ if let sizeString
= dict[ "UILaunchImageSize" ], let imageOrientation
= dict[ "UILaunchImageOrientation" ]
{ let imageSize
= CGSizeFromString (sizeString) if CGSizeEqualToSize (imageSize,
viewSize) &&
viewOrientation == imageOrientation { if let imageName
= dict[ "UILaunchImageName" ]
{ return imageName } } } } } } return nil } override func didReceiveMemoryWarning()
{ super .didReceiveMemoryWarning() } } |
原文出自:www.hangge.com 轉載請保留原文鏈接:http://www.hangge.com/blog/cache/detail_1246.html