静态成员'过渡'不能在类型' UIView'

时间:2017-06-22 04:15:55

标签: swift uiview static instance transition

我尝试对多个元素使用视图转换但是会出现这个错误: 静态成员'过渡'不能用于' UIView'类型的实例。 我已经阅读了类似的讨论,但无法为我的案例实施这些讨论。 你能帮帮我吗?

这是我的代码:

  func flip03() {

    for item in aGameObjects {


        if positionCounter == 0 {



            item.transition(from: backImageView, to: frontImageView, duration: 1, options: .transitionFlipFromRight, completion: nil)

            frontImageView.image = UIImage(named: "apple")!.withRenderingMode(.alwaysTemplate)
            frontImageView.tintColor = UIColor.occasionalColor

            positionCounter = 1

        } else {

            item.transition(from: frontImageView, to: backImageView, duration: 1, options: .transitionFlipFromRight, completion: nil)

            positionCounter = 0
        }


    }


}

enter image description here

1 个答案:

答案 0 :(得分:1)

那是因为transition是一个类方法,你可以像这样调用类方法:

UIView.transition(from: backImageView, to: frontImageView, duration: 1, options: .transitionFlipFromRight, completion: nil)

有关类方法的更多详细信息,请参阅:

Calling Type Methods Within An Instance Method

还有:

What is the difference between static func and class func in Swift?