【问题标题】:cannot convert value of type UIImage to expected argument type string无法将 UIImage 类型的值转换为预期的参数类型字符串
【发布时间】:2016-07-10 23:13:55
【问题描述】:

我对 swift 有一些问题。

Ground = SKSpriteNode(imageNamed: "#imageLiteral(resourceName: "Ground")")

这里说“无法将 UIImage 类型的值转换为预期的参数类型字符串”我该如何解决这个问题

【问题讨论】:

    标签: swift xcode sprite-kit swift2 xcode8


    【解决方案1】:

    我在做:

    profileImgView.image = UIImage(named: #imageLiteral(resourceName: "default_UserImage"))
    

    应该是这样的:

    profileImgView.image = #imageLiteral(resourceName: "default_UserImage")
    

    imageLiteral 已经返回 UIImage。

    【讨论】:

      【解决方案2】:

      也许我遗漏了一些东西,但你为什么要添加这个?

      #imageLiteral(resourceName: 
      

      正确的语法是

      let ground = SKSpriteNode(imageNamed: "Ground")
      

      【讨论】:

      • 当我执行“让”或“字符串”时,我试图在屏幕底部获取“地面”图片,它告诉我添加一个;,无论我有多少键入它总是想要一个。那段代码在override func didMove(to view: SKView) 里面,我在class GameScene: SKScene { 里面有一个var Ground = SKSpriteNode() 我所做的只是在Xcode 中启动一个游戏项目,到目前为止我只写了这个。
      • 所以当我使用那行代码时我选择了 img
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 2017-04-03
      • 2021-05-29
      相关资源
      最近更新 更多