当我尝试在2个UIImageViews之间进行修改时,你能帮我解释为什么我的代码不能正常工作吗?
这是我的代码:
// Creating falling objects
@objc func creating(_ timer: Timer) {
for (index, imageView) in images.enumerated() {
if imageView == nil {
let fallingObjectImageView = UIImageView(image: #imageLiteral(resourceName: "PoundImage"))
fallingObjectImageView.contentMode = .scaleAspectFill
fallingObjectImageView.clipsToBounds = true
let randomX = CGFloat(drand48()) * view.frame.maxX
fallingObjectImageView.frame = CGRect(x: randomX, y: -30, width: 50, height: 50)
view.addSubview(fallingObjectImageView)
images[index] = fallingObjectImageView
// This IF is not working (I dont know why)
if (fallingObjectImageView.frame.intersects(playerImageView.frame)) {
print("HIT HIT !")
}
break
}
}
}
谢谢!