아래 링크를 통해 패키지SPM를 추가한다.
https://github.com/airbnb/lottie-ios
GitHub - airbnb/lottie-ios: An iOS library to natively render After Effects vector animations
An iOS library to natively render After Effects vector animations - GitHub - airbnb/lottie-ios: An iOS library to natively render After Effects vector animations
github.com
- 에어비앤비가 후원하는 곳이라고 해서 airbnb가 붙은듯함
위에 링크를 통해 다운받았으면 import를 해서 사용할 준비를 해준다.
import Lottie
다음으로 다운받은 json 파일을 이름으로 정해서 아래처럼 애니메이션 뷰를 만들어준다.
let animationView = LottieAnimationView(name: "animation.json")
다음처럼 subView에 추가하여 화면에 띄울 수 있다.
func showAnimation(){
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
let viewWidth: CGFloat = 100
let viewHeight: CGFloat = 100
let xPosition = (screenWidth - viewWidth) / 2
let yPosition = (screenHeight - viewHeight) / 2
self.animationView.frame = CGRect(x: xPosition, y: yPosition, width: 100, height: 100)
self.animationView.contentMode = .scaleAspectFill
self.view.addSubview(self.animationView)
self.animationView.play()
self.animationView.loopMode = .loop
}
func stopAnimation(){
animationView.stop()
}
'swift' 카테고리의 다른 글
swift - 꾹 눌렀을때 메뉴 나타나게하기 UIContextMenuConfiguration (0) | 2023.08.14 |
---|---|
swift - vapor (mongodb연결하기) (0) | 2023.08.11 |
swift - 연락처 접근하기 (0) | 2023.07.22 |
swift - Vision 프레임워크를 이용한 물체 인식 (0) | 2023.07.20 |
swift - AVCaptureSession (0) | 2023.07.19 |