I have a UIImageView (stick) on top of my screen, and when the view appears, it animates a movement through the whole screen, until the end of it. In the middle of the screen there is a UIButton (hand) that I will press whenever the image that is going down is on top of this button. Here's my code:
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")
}
}
The touchHand method is when I touch the UIButton in the middle of the screen. Problem is, it's not working! I println'ed the stick.frame and it's not changing... I also tried animating through the YConstraint that I have and still not working because it just stays the same even though it's moving... Any ideas? Thanks
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")
}
}