[iOS] Lottie ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น๋ฐฉ๋ฒ - ๋ฐ์น์คํฌ๋ฆฐ ๋ง๋ค๊ธฐ_์ฝ๋๋ฒ ์ด์ค
ํํ๋ก์ ํธ ๋ ๋ด๊ฐ ๋งก์ ๋ถ๋ถ์ ๊ตฌํ์ด ๋๋์
๋ฐ์น์คํฌ๋ฆฐ์ด ์์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ ์ฐพ์ ๋ณธ ๋ด์ฉ์ ์ ๋ฆฌํด๋ณธ๋ค.
Lottie๋ gif์ ๊ฐ์ ์ ๋๋ฉ์ด์ ์ JSON ํ์์ผ๋ก ์์ด๋น์ค๋น์์ ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค.
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ importํ๋ ๋ฐฉ๋ฒ์ ์ฝ์ฝ์ํ, ์นด๋ฅดํ๊ณ , SPM ๋ฑ์ด ์์ง๋ง
๋๋ ๊ฐ์ธ์ ์ผ๋ก SPM์ด ๊ฐ๋จํด์ ์ด ๋ฐฉ๋ฒ์ผ๋ก ์ถ๊ฐํด๋ณด๋ ค๊ณ ํ๋ค.
1. ๊ณต์ ๊นํ๋ธ์์ ๋งํฌ ๋ณต์ฌ
https://github.com/airbnb/lottie-ios
2. project์์ packages์ ์ถ๊ฐํด์ค๋ค.
3. Lottie ํํ์ด์ง์์ ์ ๋๋ฉ์ด์ ๊ฒ์ ํ ํ์ผ ์ ์ฅ
4. Xcode์์ Assets ํ๋จ์ JSONํ์ผ ์ถ๊ฐ
5. import Lottie
import Lottie
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//๋ฐ์น์คํฌ๋ฆฐ
let animationView: LottieAnimationView = .init(name: "coffee") //JSON ํ์ผ๋ช
animationView.frame = self.view.bounds //์ ์ฒดํ๋ฉด
animationView.contentMode = .scaleAspectFit //ํ๋ฉด์ ๊ฐ๋ ์ฐจ๊ฒ
self.view.addSubview(animationView)
animationView.play{ (finished) in
if finished {
// ์ ๋๋ฉ์ด์
์ด ์ข
๋ฃ๋๋ฉด animationView๋ฅผ ์ ๊ฑฐ
animationView.removeFromSuperview()
self.setupCoffeeListView()
}
}
}
}
//์ด ๋ฉ์๋๋ฅผ ํธ์ถํด์ผ ์ ๋๋ฉ์ด์
์คํ์ด ๋จ
//๋ฐฉ๋ฒ1
self.animationView.play()
//๋ฐฉ๋ฒ2
animationView.play {(finish) in
...
}
// ์ ๋๋ฉ์ด์
0.5๋ฐฐ์ ์ฌ์
animationView.animationSpeed = 0.5
// ์ ๋๋ฉ์ด์
2๋ฐฐ์ ์ฌ์
animationView.animationSpeed = 2
// ๋ฌดํ ์คํ
animationView.loopMode = .loop
// 1๋ฒ๋ง ์คํ
animationView.loopMode = .playOnce
// 2๋ฒ ์คํํ๊ณ ์ข
๋ฃ
animationView.loopMode = .repeat(2)
textField์ UIKeyboardType (0) | 2024.07.08 |
---|---|
[iOS] toast message - ๋ฐฐ๋ฌ์ ๋ฏผ์กฑ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์ต๋๋ค (0) | 2024.07.07 |
[UIKit] UITableView ์ฝ๋๋ฒ ์ด์ค ์ฌ์ฉ๋ฒ (0) | 2024.07.04 |
[UIKit] ํํ๋ชจ๋ฌ ๊ตฌํ(Scrollable Bottom Sheet) - SheetPresentationController (0) | 2024.07.03 |
[ UIKit ] addTarget(_:action:for:) ๋ฉ์๋ (0) | 2024.06.30 |