iT邦幫忙

2021 iThome 鐵人賽

0
自我挑戰組

一個令我自豪的App完成之路系列 第 31

Loading載入 Lottie實作 Day31

今天要把Loading加入TableView載入之前

昨天說了動畫的部分會用Lottie來做,出現階段會是在ViewDidLoad()

那麼今天就來實作!

今天實作的路上遇到一點困難,雖然解決了但是還是莫名

前天說了新增一個Lottie,拖一個@IBOulet作為顯示

但是我今天試了很多次,就是會出現Bug,都會找不到我的@IBOulet

所以我只好使用純Programming的方式製作

這是建構出animationView
原本是使用@IBOutlet

// LoadingViewController內

override func viewDidLoad(){

let animation = AnimationView(name:"73734-logo-anmation")
animation.frame = CGRect(x:0,:y:0,width:300,height:200)
animation.center = view.center
animation.loopMode = .loop
animation.animationspeed = 1
self.view.addSubview(animation)
animation.play()
view.background = UIColor.init(white:5, alpha:0.6)

}

在要顯示的VC中的ViewDidLoad()階段

override func viewDidLoad(){
	super.viewDidLoad()
	// 使用LoadingAnimation function作為顯示
	LoadingAnimation()
}
func LoadingAnimation(){
	let Loading = LoadingViewController()
	Loading.modalPresentationStyle = .overCurrentContext
	Loading.modalTransitionStyle = .crossDissove
	// 使用Present方式呈現
	// 使用tabBarController是因為這個Present stack的viewController會是tabBarController
	self.tabBarController?.present(Loading,animation: true,completion:nil)
}

成果展示:

https://i.imgur.com/ulKdpB9.gif


上一篇
App生命週期使用時機 Day 30
下一篇
Final Day
系列文
一個令我自豪的App完成之路32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言