1

I try to use view transition for multiple element but get this mistake: Static member 'transition' cannot be used on instance of type 'UIView'. I've read similar discussions but couldn't implement them for my case. Could you help me?

Here is my code:

  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

Roman
  • 759
  • 2
  • 9
  • 23

1 Answers1

1

That's because transition is a class method, you can call class method like this:

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

for more details on class methods see:

Calling Type Methods Within An Instance Method

and also:

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

developer_hatch
  • 15,898
  • 3
  • 42
  • 75