我尝试对多个元素使用 View 过渡,但出现以下错误: 静态成员“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
}
}
}
最佳答案
那是因为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?
关于swift - 静态成员 'transition' 不能用于类型 'UIView' 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44690038/