在我的应用程序中,我有几个按钮,在按下一个单独的按钮后,它们会移动到 UIView 动画中的新位置。动画本身完美运行,但问题是,在动画之后,四个按钮停止响应触摸操作。这是我当前的代码:
UIView.animate(withDuration: 1.0, delay: 0.0, options: [.allowUserInteraction], animations: {
self.hexagon.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2)
self.tileB.center.x += self.tileB.bounds.width
self.tileB.center.y += self.tileB.bounds.height
self.tileF.center.x -= self.tileF.bounds.width
self.tileF.center.y += self.tileF.bounds.height
self.tileH.center.x -= self.tileH.bounds.width
self.tileH.center.y -= self.tileH.bounds.height
self.tileD.center.x += self.tileD.bounds.width
self.tileD.center.y -= self.tileD.bounds.height
}, completion: nil)
我尝试了很多其他方法,包括设置框架和边界,但没有一个能正常工作。
最佳答案
The animation itself works perfectly, but the problem is, after the animation, the four buttons stop responding to touch actions
原因可能是在动画之后,按钮已经移出了它们的父 View 的边界。其父 View 之外的 View 是不可触及的,即使它是可见的。
确认这一点的一种方法是将 super View 的 clipsToBounds
设置为 true
并执行动画。按钮将在动画结束时消失,证明它们已移出父 View 。
关于ios - UIButtons 的动画位置导致它们停止接收触摸 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50652126/