티스토리 뷰

반응형

Lottie는 iOS, Android 및 웹 애플리케이션을 위한 강력하고 가벼운 애니메이션 라이브러리입니다. Bodymovin 플러그인을 사용하여 JSON 파일로 내보낸 Adobe After Effects로 만든 애니메이션을 렌더링하고 재생할 수 있습니다. Lottie는 기존의 이미지 시퀀스나 사용자 지정 코드 없이 고품질의 대화형 및 확장 가능한 애니메이션을 앱에 추가할 수 있는 간단하고 효율적인 방법을 제공합니다.

다음은 몇 가지 주요 Lottie 기능에 대한 간단한 설명입니다.

 

1. 고품질 애니메이션: Lottie는 높은 수준의 디테일로 벡터 애니메이션을 렌더링하여 모든 화면 크기나 해상도에서 선명하고 매끄럽게 보입니다.

2. 대화형 애니메이션: Lottie는 대화형 애니메이션을 지원하므로 사용자가 제스처나 기타 입력을 사용하여 애니메이션의 재생, 속도 및 진행을 제어할 수 있습니다.

3. 작은 파일 크기: Lottie 애니메이션은 일반적으로 기존 이미지 시퀀스에 비해 파일 크기가 훨씬 작기 때문에 다운로드 속도가 빠르고 리소스 집약도가 낮습니다.

4. 손쉬운 통합: Lottie는 애니메이션 재생, 중지 및 제어를 위한 간단한 API를 제공하여 모든 앱에 쉽게 통합할 수 있습니다.

다음은 Lottie를 사용하여 UIViewController에서 애니메이션을 로드하고 재생하는 간단한 예입니다.

 

1. Swift 파일 상단에서 Lottie를 가져옵니다.

import Lottie

2. Lottie 애니메이션을 로드하고 재생하는 함수를 만듭니다.

func playLottieAnimation() {
    // Create an AnimationView instance
    let animationView = AnimationView()

    // Load the animation JSON file
    if let animation = Animation.named("exampleAnimation") {
        // Set the animation to the AnimationView
        animationView.animation = animation

        // Set the loop mode and playback speed
        animationView.loopMode = .loop
        animationView.animationSpeed = 1.0

        // Add the AnimationView to the view hierarchy
        view.addSubview(animationView)

        // Define the size and position of the AnimationView
        animationView.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            animationView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            animationView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            animationView.widthAnchor.constraint(equalToConstant: 200),
            animationView.heightAnchor.constraint(equalToConstant: 200)
        ])

        // Play the animation
        animationView.play()
    } else {
        print("Error: Unable to load animation")
    }
}

이 예제에서는 AnimationView 인스턴스를 생성하고 "exampleAnimation"이라는 Lottie 애니메이션 JSON 파일을 로드합니다. 애니메이션의 루프 모드를 .loop로 설정하여 계속 재생되도록 하고 애니메이션 속도를 1.0으로 설정합니다. 그런 다음 뷰 계층 구조에 AnimationView를 추가하고 크기와 위치를 정의하고 애니메이션을 재생합니다.

함수를 실행하려면 보기 컨트롤러의 viewDidLoad 메서드와 같이 코드 내의 원하는 위치에서 playLottieAnimation()을 호출하기만 하면 됩니다. Swift Package Manager, CocoaPods 또는 Carthage를 사용하여 Lottie 패키지를 설치하고 특정 설치 방법에 대한 설정 지침을 따르십시오.

 

Lottie JSON 파일을 프로젝트 리소스에 추가하는 것을 잊지 마세요.

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
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
글 보관함