gpt4 book ai didi

ios - 如何为 UITableViewCell 实现摇动动画

转载 作者:可可西里 更新时间:2023-11-01 06:24:41 25 4
gpt4 key购买 nike

如何让一个UITableViewCell从左边摇到右边?

我想让用户知道“这个 Action 是不可能的”!

最佳答案

谢谢汉斯!这里是 Swift 和 UITableViewCell 的扩展形式,持续时间和路径长度可选。

import UIKit
import QuartzCore

extension UITableViewCell {
func shake(duration: CFTimeInterval = 0.3, pathLength: CGFloat = 15) {
let position: CGPoint = self.center

let path: UIBezierPath = UIBezierPath()
path.moveToPoint(CGPointMake(position.x, position.y))
path.addLineToPoint(CGPointMake(position.x-pathLength, position.y))
path.addLineToPoint(CGPointMake(position.x+pathLength, position.y))
path.addLineToPoint(CGPointMake(position.x-pathLength, position.y))
path.addLineToPoint(CGPointMake(position.x+pathLength, position.y))
path.addLineToPoint(CGPointMake(position.x, position.y))

let positionAnimation = CAKeyframeAnimation(keyPath: "position")

positionAnimation.path = path.CGPath
positionAnimation.duration = duration
positionAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)

CATransaction.begin()
self.layer.addAnimation(positionAnimation, forKey: nil)
CATransaction.commit()
}
}

关于ios - 如何为 UITableViewCell 实现摇动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21024201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com