Reputation: 29
I'm making a simple app that involves a button moving across the screen and I would like for the user to be able to click it while it moves. I have this:
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)
}
Which gives me the "use of unresolved identifier UIViewAnimationOptionAllowUserInteraction"
error.
I tried options: UIViewAnimationOptions.AllowUserInteraction
which compiles, but doesn't allow the button to be clickable during animations.
I visited developer portal but I'm fairly new to Swift. What am I doing wrong? Thanks!
Upvotes: 2
Views: 892
Reputation: 104082
You can use .AllowUserInteraction for the option, but that won't fix your problem. When you do an animation (with animateWithDuration) the view's frame is immediately set to the final position, so the touch point will actually be there, not where you see the moving view. If you want the user to be able to interact with the button, you'll have to animate it by incrementally moving it with a timer.
Upvotes: 2