【问题标题】:Static member 'transition' cannot be used on instance of type 'UIView'静态成员“transition”不能用于“UIView”类型的实例
【发布时间】:2017-11-25 04:20:02
【问题描述】:

我尝试对多个元素使用视图转换,但出现以下错误: 静态成员“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
        }


    }


}

【问题讨论】:

    标签: swift uiview static instance transition


    【解决方案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?

    【讨论】:

    • 谢谢,但这并不能帮助我通过数组的所有项目来获得这种转换。
    猜你喜欢
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多