【问题标题】:Animating a UIImageView movement and then use CGRectIntersection动画 UIImageView 运动,然后使用 CGRectIntersection
【发布时间】:2015-07-15 19:21:51
【问题描述】:

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

【问题讨论】:

    标签: ios swift cgrectintersectsrect


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2018-06-16
      • 1970-01-01
      相关资源
      最近更新 更多