动画UIImageView的运动,然后使用CGRectIntersection



我有一个UIImageView (stick)在我的屏幕上,当视图出现时,它通过整个屏幕动画运动,直到它的结束。在屏幕中间有一个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时。问题是,它不管用!我打印了木棒框架,它没有改变……我也尝试过通过我拥有的y约束来制作动画,但仍然不起作用,因为即使它在移动,它也保持不变……什么好主意吗?由于

这与这个问题非常相似,所以下面应该可以帮助你:

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

最新更新