swift - 表达式类型 UIImage 在没有更多上下文的情况下不明确

标签 swift sprite-kit uiimage

以下代码会在这一行生成此问题标题中显示的错误:for (index, image) in (backgroundImages) {

有人可以建议如何消除这个错误

init!(backgroundImages:[UIImage], size:CGSize, scrollingDirection:ScrollingDirection, startingSpeed:CGFloat, speedDecreaseFactor:CGFloat) {
    self.backgrounds = []
    self.clonedBackgrounds = []
    self.speeds = []
    self.numberOfBackgrounds = (backgroundImages.count)
    self.scrollingDirection = scrollingDirection
    super.init(texture: nil, color:UIColor.clear, size: size)

    let zPos = 1.0 / CGFloat(numberOfBackgrounds)
    var currentSpeed = startingSpeed
    self.position = CGPoint(x:self.size.width/2, y:self.size.height/2)
    self.zPosition = -100

    for (index, image) in (backgroundImages) {
        let background = SKSpriteNode(texture: SKTexture(CGImage: image.CGImage), size:size)

        background.zPosition = self.zPosition - (zPos + (zPos * CGFloat(index)))
        background.position = CGPoint(x:0,y:0)
        let clonedBackground = background.copy() as! SKSpriteNode
        var clonedBackgroundX = background.position.x
        var clonedBackgroundY = background.position.y

        switch (scrollingDirection) {
        case .Right:
            clonedBackgroundX = -background.size.width
        case .Left:
            clonedBackgroundX = background.size.width
        default:
            break
        }

最佳答案

你的意思可能是 for (index, image) in backgroundImages.enumerated()

编译器不知道如何将 backgroundImages 的元素解构为 (index, image)

关于swift - 表达式类型 UIImage 在没有更多上下文的情况下不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46496029/

相关文章:

arrays - 从 UIImage 数组获取值并转换为字符串

ios - 添加横幅以告知应用程序正在后台运行 - iOS

ios - UIView不圆角,UITableView单元格回收

swift - 为 tableviewcell 设置图像会减慢 Swift 中的滚动速度

swift - 如何快速将GameCenter放到应用程序上?

cocoa - TouchesBeganWithEvent 未在 SKScene 中调用

ios - 将图像添加到ios工具栏的UIBarButtonItem

swift - 按钮不使用其中的代码?

ios - UIView removeFromSuperview 正在调用 didMoveToSuperview

sprite-kit - 有没有办法改变 SpriteKit 调试数据的字体和位置?