This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9051-beginning-ios-animations/lessons/22
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9051-beginning-ios-animations/lessons/22
Hi,
When running the project from episode 22, entitled “Setting Up the Animator” in the Beginning iOS Animations tutorial, the project has a runtime error on line 129. I get an error message stating Could not cast value of type ‘UIView’ to ‘UIImageView’ .
Currently running Xcode Version 11.0.
Warm regards,
Brandon
Hi Brandon,
Thanks for bringing this to our attention! The starter project is using tags to identify the image views, and tags aren’t working in the same way they had been when the code was written. Now, two of listView's
subviews end up with the same tag, and crashing ensues when the wrong subview is cast to UIImageView
. I’ll make a note to address that when this course is next updated.
For now, you can replace the entire for loop that starts on line 117 in ViewController.swift with the following:
listView.subviews
.filter { $0 is UIImageView }
.enumerated()
.forEach { i, imageView in
imageView.frame = CGRect(
x: CGFloat(i) * itemWidth + CGFloat(i+1) * horizontalPadding, y: 0.0,
width: itemWidth, height: itemHeight
)
}
I’ll replace the projects for this episode with the updated code. Just let me know if you have any more questions. Thanks again!