Reputation: 343
I want to have my button moved with 20 pixels to the left and I want it after 0.25 second back at the original spot. This is what i got so far:
@IBOutlet weak var Like: UIButton!
UIView.animate(withDuration: 0.25,
animations: {
var likeframe = self.Like.frame
likeframe.origin.x -= 20
},
completion: { _ in
UIView.animate(withDuration: 0.25) {
var likeframe = self.Like.frame
likeframe.origin.x += 20
}
})
Please help!
Upvotes: 1
Views: 46
Reputation: 100503
You need to change the frame itself
UIView.animate(withDuration: 0.25,animations: {
self.Like.frame = self.Like.frame.offsetBy(dx:-20,dy:0)
}) { _ in
UIView.animate(withDuration: 0.25 , animations: {
self.Like.frame = self.Like.frame.offsetBy(dx:20,dy:0)
})
}
Upvotes: 2
Reputation:
Change the frame and use the delay function to delay the animation
UIView.animate(withDuration: 0.25,
animations: {
Like.frame.origin.x -= 20
},
completion: { _ in
UIView.animate(withDuration: 0.25, delay: 0.25, options: [], animations: {
Like.frame.origin.x += 20
}, completion: nil)
})
Upvotes: 0