我正在制作一个简单的应用程序,涉及一个按钮在屏幕上移动,我希望用户能够点击它,而它移动。我有这个:
func bonus ()
{
UIView.animateWithDuration(14,
delay: 0.1,
options: UIViewAnimationOptionsAllowUserInteraction,
animations: {
self.bonusbutton.center = CGPointMake(self.bonusbutton.center.x + 1000, self.bonusbutton.center.y)
}, completion : nil)
}这给了我"use of unresolved identifier UIViewAnimationOptionAllowUserInteraction"错误。
我尝试了options:UIViewAnimationOptions.AllowUserInteraction,它可以编译,但不允许在动画过程中点击按钮。
我访问过developer portal,但我对Swift还是个新手。我做错了什么?谢谢!
发布于 2015-01-23 07:46:47
您可以使用.AllowUserInteraction作为选项,但这不会解决您的问题。当您使用animateWithDuration制作动画时,视图的帧将立即设置为最终位置,因此触摸点实际上将在那里,而不是您看到移动视图的位置。如果您希望用户能够与按钮进行交互,则必须通过使用计时器递增地移动按钮来为其设置动画。
https://stackoverflow.com/questions/28100684
复制相似问题