【问题标题】:Swift lottie animation does not play some json files that play on the androidswift lottie 动画不播放一些在android上播放的json文件
【发布时间】:2017-03-16 13:50:43
【问题描述】:

我尝试使用 swift 和 lottie 使用 bodymovin 制作播放从 Adob​​e After Effects 导出的动画 json 的 ios 应用程序。 我制作了具有相同功能的 android 应用程序。 在android上没有问题,但是使用相同的json文件我无法在ios上播放json动画。

在 ios 上,我的应用程序适用于示例项目或 lottie 中的另一个 json 文件。

如果有谁有这方面的经验,请帮助我。

animationView = LAAnimationView.animationNamed("New_Anim2") 
animationView?.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 250) 
animationView?.contentMode = .scaleAspectFill
animationView?.backgroundColor = .white
self.view.addSubview(animationView!)        
animationView?.play()

完整的源代码和json文件链接:enter link description here

【问题讨论】:

  • 您得到以上问题的解决方案了吗?如果你有请与我分享。
  • 你知道这个古怪的问题吗? github.com/airbnb/lottie-ios/issues/498
  • @Fattie 我通过 Google Meet 聊天从 Mr.Fattie 获得了 lottie 文件链接。设计师 。我使用此链接下载 lottie 动画 json 文件并导入新的演示应用程序。它适用于创建新的演示应用程序,但是当我将此 json 文件添加到我现有的项目中时。它不起作用。
  • @NarendraJagne 设计师在发送给您之前必须压缩文件
  • @Fattie 他给我发了 json zip 文件但没有用

标签: ios swift animation


【解决方案1】:

我最近正在和 Lottie 一起开发一个应用程序,看看这种使用动画的方式,顺便说一句,你必须将 json 文件复制到项目文档大纲中而不是资产文件夹中。

let animationView = LOTAnimationView(name: "splash_loader")
        self.AnimationView.addSubview(animationView)
        self.AnimationView.contentMode = UIViewContentMode.scaleAspectFill
        animationView.sizeToFit()
       // animationView.sizeThatFits(AnimationView.frame.size)
        animationView.play{ (finished) in
            // Do Something
            animationView.removeFromSuperview()
            self.AnimationView.willRemoveSubview(animationView)
        }

【讨论】:

    【解决方案2】:

    首先将json文件放入你的项目中:

    let jsonName = "jsonFileName"
    let animation = Animation.named(jsonName)
    
    // Load animation to AnimationView
    let animationView = AnimationView(animation: animation)
    animationView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
    
    // Add animationView as subview
    view.addSubview(animationView)
    
    // Play the animation
    animationView.play()
    

    【讨论】:

      猜你喜欢
      • 2020-10-24
      • 2022-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多