【问题标题】:Initializer for conditional binding must have Optional type, not 'AnimationView'条件绑定的初始化程序必须具有 Optional 类型,而不是“AnimationView”
【发布时间】:2020-07-20 16:02:09
【问题描述】:

这是什么意思?

条件绑定的初始化器必须是 Optional 类型,而不是 'AnimationView'

一直在努力弄清楚我的意思以及如何解决它? 任何帮助将不胜感激

    override func viewDidLoad() {
    super.viewDidLoad()
            
    if let animationView = AnimationView(name: "breathing") {
        animationView.frame = CGRect(x: 0, y: 0, width: 400, height: 400)
        animationView.center = self.view.center
        animationView.contentMode = .scaleAspectFill
        
        view.addSubview(animationView)
    
        animationView.play()
    }

【问题讨论】:

标签: swift uikit lottie


【解决方案1】:

错误很明显AnimationView(name: "breathing") 不是可选的。

替换:

if let animationView = AnimationView(name: "breathing") {

与:

let animationView = AnimationView(name: "breathing")

【讨论】:

  • 刚试过这个,它工作了一段时间,然后错误说尾随闭包传递给'AnimationCacheProvider'类型的参数?不接受关闭
  • @libbywinfield 避免在开头和结尾使用花括号。
猜你喜欢
  • 2015-10-19
  • 2016-09-15
  • 1970-01-01
  • 1970-01-01
  • 2019-08-28
  • 2021-04-26
  • 2016-01-27
  • 2018-03-05
  • 1970-01-01
相关资源
最近更新 更多