我想让按钮向左移动20个像素,我希望在原点后0.25秒返回。这就是我到目前为止所得到的:
@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
}
})
请帮助!
答案 0 :(得分:2)
您需要更改框架本身
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)
})
}
答案 1 :(得分:0)
更改帧并使用延迟功能延迟动画
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)
})