簡體   English   中英

Swift 3 - 按鈕動畫跳轉到右側

[英]Swift 3 - Button Animation Jumps to the right

點擊后,我將此按鈕設置為“反彈”。 它確實有效,但是一旦動畫結束,它就跳到右邊,然后回到它應該的位置。 我認為最好是運行此代碼(連接到按鈕)以便自己查看。 我正在iPad上測試我的應用程序。 基本上,我想知道為什么它會在動畫制作之后跳到他身邊。 這是我的代碼:

@IBAction func randomiseButton(_ sender: Any) {
    if self.choices.isEmpty == true {
        let theButton = sender as! UIButton
        let bounds = theButton.bounds
        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: .curveEaseInOut, animations: {
            theButton.bounds = CGRect(x: bounds.origin.x - 20, y: bounds.origin.y, width: bounds.size.width + 60, height: bounds.size.height)
        }) { (success:Bool) in
            if success {
                UIView.animate(withDuration: 0.5, animations: {
                    theButton.bounds = bounds
                })
            }
        }

當在第一個if語句之外檢查數組“choices”是否為空時,也會發生這種情況

干杯馬特

好吧就像問了這個問題后10分鍾我搞亂了我的代碼,我改變了最后一個動畫

UIView.animate(withDuration: 0.5, 

UIView.animate(withDuration: 0,

不知道為什么,但這似乎做了伎倆!

刪除完成塊。

UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: .curveEaseInOut, animations: {
    theButton.bounds = CGRect(x: bounds.origin.x - 20, y: bounds.origin.y, width: bounds.size.width + 60, height: bounds.size.height)
})

PS

編碼:

UIView.animate(withDuration: 0,

意味着您的動畫將在0秒內執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM