[英]Swift: UITableViewCell bounce from right to left animation
幾周以來,我一直在嘗試在用戶點擊單元格時在表格視圖中實現單元格從右到左的反彈動畫,就像 Instagram 和 Snapchat iOS 應用程序一樣。
由於我對 Swift 中的動畫缺乏經驗,並且經過數周的研究試圖找到有關如何實現此類動畫的一些信息,我一直無法弄清楚如何做到這一點。
Swift 動畫的初學者應該在哪里學習如何創建這樣的動畫或任何有用的動畫(即點擊按鈕),以創建更好的用戶體驗?
我很感激任何幫助。 謝謝。
斯威夫特 4:
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.05
animation.repeatCount = 3
animation.autoreverses = true
animation.speed = 0.8
animation.fromValue = NSValue(cgPoint: CGPoint(x: cell.center.x - 3, y: cell.center.y))
animation.toValue = NSValue(cgPoint: CGPoint(x: cell.center.x + 3, y: cell.center.y))
cell.layer.add(animation, forKey: "position")
查看核心動畫: https : //developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html
這是一個在點擊/選擇時從一側到另一側設置單元格動畫的示例。
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.05
animation.repeatCount = 3
animation.autoreverses = true
animation.speed = 0.8
animation.fromValue = NSValue(CGPoint: CGPointMake(selectedCell!.center.x - 3, selectedCell!.center.y))
animation.toValue = NSValue(CGPoint: CGPointMake(selectedCell!.center.x + 3, selectedCell!.center.y))
selectedCell!.layer.addAnimation(animation, forKey: "position")
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.