diff --git a/li/li.xcodeproj/project.pbxproj b/li/li.xcodeproj/project.pbxproj index 01d3393..4a40f9d 100644 --- a/li/li.xcodeproj/project.pbxproj +++ b/li/li.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 6FB2E3DA2AB9D9A600884499 /* SF-Pro.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 6FB2E3D92AB9D9A600884499 /* SF-Pro.ttf */; }; 6FB2E3DC2AB9DB4500884499 /* AppleSDGothicNeo.ttc in Resources */ = {isa = PBXBuildFile; fileRef = 6FB2E3DB2AB9DB4500884499 /* AppleSDGothicNeo.ttc */; }; 6FB2E3DE2AB9DBD000884499 /* FontManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FB2E3DD2AB9DBD000884499 /* FontManager.swift */; }; + A924BC0E2ADCEDCD00D9FC62 /* LottieManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A924BC0D2ADCEDCD00D9FC62 /* LottieManager.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -43,6 +44,7 @@ 6FB2E3DB2AB9DB4500884499 /* AppleSDGothicNeo.ttc */ = {isa = PBXFileReference; lastKnownFileType = file; path = AppleSDGothicNeo.ttc; sourceTree = ""; }; 6FB2E3DD2AB9DBD000884499 /* FontManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontManager.swift; sourceTree = ""; }; 6FB2E3E02AB9E97800884499 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + A924BC0D2ADCEDCD00D9FC62 /* LottieManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LottieManager.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -73,6 +75,7 @@ 6F1762D82AA48598009D0040 /* LocationManager.swift */, 6F22E7352AAC4E33006A0528 /* HapticManager.swift */, 6FB2E3DD2AB9DBD000884499 /* FontManager.swift */, + A924BC0D2ADCEDCD00D9FC62 /* LottieManager.swift */, ); path = Manager; sourceTree = ""; @@ -222,6 +225,7 @@ 6F2501572AA079EA00DA8E8F /* ContentView.swift in Sources */, 6F84329B2AA77115000760AC /* HourlyForcastView.swift in Sources */, 6F1762D92AA48598009D0040 /* LocationManager.swift in Sources */, + A924BC0E2ADCEDCD00D9FC62 /* LottieManager.swift in Sources */, 6F1762DB2AA4F0FD009D0040 /* SevenDayForecastView.swift in Sources */, 6F1762D42AA47D00009D0040 /* MainView.swift in Sources */, 6F2501552AA079EA00DA8E8F /* liApp.swift in Sources */, diff --git a/li/li/Manager/LottieManager.swift b/li/li/Manager/LottieManager.swift new file mode 100644 index 0000000..69773f3 --- /dev/null +++ b/li/li/Manager/LottieManager.swift @@ -0,0 +1,96 @@ +// +// LottieManager.swift +// li +// +// Created by OLING on 2023/10/16. + +import Foundation +import Lottie +import SwiftUI +import UIKit + +struct Lottiefile : UIViewRepresentable { + typealias UIViewType = UIView + + var filename: String + var loopState: Bool + var playState: Bool + + func makeUIView(context: UIViewRepresentableContext) -> UIView { + let view = UIView(frame: .zero) + //4. Add animation + let animationView = LottieAnimationView() + //사용자 애니메이션 파일명 + animationView.animation = LottieAnimation.named(filename) + //애니메이션 크기가 적절하게 조정될 수 있도록 + animationView.contentMode = .left + if loopState { + animationView.loopMode = .loop + } + //애니메이션 재생 + animationView.play() + + //컨테이너의 너비와 높이를 자동으로 지정할 수 있도록 + animationView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(animationView) + + //5. 자동완성 기능 + NSLayoutConstraint.activate([ + //레이아웃의 높이와 넓이의 제약 + animationView.widthAnchor.constraint(equalTo: view.widthAnchor), + animationView.heightAnchor.constraint(equalTo: view.heightAnchor) + ]) + + return view + } + + func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext) { + + } +} + +struct LottiePlayState : UIViewRepresentable { + + func makeUIView(context: Context) -> Lottie.LottieAnimationView { + let view = UIView(frame: .zero) + //4. Add animation + let animationView = LottieAnimationView() + //사용자 애니메이션 파일명 + animationView.animation = LottieAnimation.named(filename) + //애니메이션 크기가 적절하게 조정될 수 있도록 + animationView.contentMode = .left + + if loopState { + animationView.loopMode = .loop + } + + + //컨테이너의 너비와 높이를 자동으로 지정할 수 있도록 + animationView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(animationView) + + //5. 자동완성 기능 + NSLayoutConstraint.activate([ + //레이아웃의 높이와 넓이의 제약 + animationView.widthAnchor.constraint(equalTo: view.widthAnchor), + animationView.heightAnchor.constraint(equalTo: view.heightAnchor) + ]) + + return animationView + } + + func updateUIView(_ uiView: Lottie.LottieAnimationView, context: Context) { + if playState { + uiView.play() + } + } + + + var filename: String + var loopState: Bool + var playState: Bool + } + + + +