动画 UIImageView 运动然后使用 CGRectIntersection

Animating a UIImageView movement and then use CGRectIntersection

我的屏幕顶部有一个 UIImageView(棒),当该视图出现时,它会在整个屏幕上动画移动,直到它结束。在屏幕中间有一个 UIButton(手),只要正在下降的图像位于此按钮的顶部,我就会按下它。 这是我的代码:

override func viewDidAppear(animated: Bool) {
    UIView.animateWithDuration(1, animations: {self.stick.center = CGPointMake(self.stick.center.x, 760)}, completion: nil)
}

@IBAction func touchHand(sender: UIButton) {
    if !CGRectIsNull(CGRectIntersection(stick.frame, hand.frame)){
        println("intersected")
    }

}

touchHand 方法是当我触摸屏幕中间的 UIButton 时。 问题是,它不起作用! 我打印了 stick.frame 并且它没有改变......我还尝试通过我拥有的 YConstraint 制作动画但仍然无法正常工作,因为即使它在移动它也保持不变......有什么想法吗? 谢谢

它与 this question 非常相似,因此以下内容应该对您有所帮助:

@IBAction func touchHand(sender: UIButton) {
    let stickPresentationFrame = (stick.layer.presentationLayer() as! CALayer).frame
    if !CGRectIsNull(CGRectIntersection(stickPresentationFrame, hand.frame)){
        println("intersected")
    }
}