如果我正在为UIButton制作动画并使用.allowUserInteraction选项,则可以点击动画结尾处最终帧的区域以与按钮进行交互,甚至在按钮进入该帧之前。点击按钮可见的位置不会触发操作,如果它在按钮动画的最终帧之外:
UIView.animate(withDuration: 9.0, delay: 0.0, options: [.curveLinear, .allowUserInteraction], animations: {
self.theButton.frame = CGRect(x: (self.view.frame.width * 0.1), y: self.theButton.frame.origin.y, width: self.theButton.frame.width, height: self.theButton.frame.height)
}, completion: nil)
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
与UIButton无关。无论是按钮还是图像视图,在动画播放期间点击它的唯一方法似乎是使用touchesBegan并测试对象的layer.presentation帧是否包含触摸位置:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first!
let touchLocation = touch.location(in: self.view)
let buttonFrame = theButton.layer.presentation()!.frame
if buttonFrame.contains(touchLocation) {
print("Tapped the button here!")
}
}