0

我的屏幕顶部有一个 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制作动画,因为即使它在移动它也保持不变......有什么想法吗?谢谢

4

1 回答 1

0

It's quite similar to this question, so the following should help you:

@IBAction func touchHand(sender: UIButton) {
    let stickPresentationFrame = (stick.layer.presentationLayer() as! CALayer).frame
    if !CGRectIsNull(CGRectIntersection(stickPresentationFrame, hand.frame)){
        println("intersected")
    }
}
于 2015-07-15T20:16:57.940 回答