PlayPauseAnimation.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import SwiftUI
  2. import Spine
  3. struct PlayPauseAnimation: View {
  4. @StateObject
  5. var controller = SpineController(
  6. onInitialized: { controller in
  7. controller.animationState.setAnimationByName(
  8. trackIndex: 0,
  9. animationName: "flying",
  10. loop: true
  11. )
  12. }
  13. )
  14. var body: some View {
  15. SpineView(
  16. from: .bundle(atlasFileName: "dragon.atlas", skeletonFileName: "dragon-ess.skel"),
  17. // from: .http(
  18. // atlasURL: URL(string: "https://github.com/esotericsoftware/spine-runtimes/raw/spine-ios/spine-ios/Example/Spine%20iOS%20Example/Assets/dragon/dragon.atlas")!,
  19. // skeletonURL: URL(string: "https://github.com/esotericsoftware/spine-runtimes/raw/spine-ios/spine-ios/Example/Spine%20iOS%20Example/Assets/dragon/dragon-ess.skel")!
  20. // ),
  21. controller: controller,
  22. boundsProvider: SkinAndAnimationBounds(animation: "flying")
  23. )
  24. .navigationTitle("Play/Pause")
  25. .navigationBarTitleDisplayMode(.inline)
  26. .toolbar {
  27. Button(action: {
  28. if controller.isPlaying {
  29. controller.pause()
  30. } else {
  31. controller.resume()
  32. }
  33. }) {
  34. Image(systemName: controller.isPlaying ? "pause.fill" : "play.fill")
  35. }
  36. }
  37. }
  38. }
  39. #Preview {
  40. PlayPauseAnimation()
  41. }