如何在iOS中制作类似react加载骨架的微光动画
我想要一个像这样的微光动画:。 (这是使用library:在WebApp中创建的) 我尝试使用带有不透明度的GradientLayer通过所有子视图创建微光动画:如何在iOS中制作类似react加载骨架的微光动画,ios,swift,cagradientlayer,Ios,Swift,Cagradientlayer,我想要一个像这样的微光动画:。 (这是使用library:在WebApp中创建的) 我尝试使用带有不透明度的GradientLayer通过所有子视图创建微光动画: gradientLayer.colors = [Colors.tokenDark20.cgColor, Colors.tokenDark10.cgColor, Colors.tokenDark20.cgColor] gradientLayer.opacity = 0.5 但我得到了动画: 更多努力: 我尝试使用库:,尝试从左到右链接
gradientLayer.colors = [Colors.tokenDark20.cgColor, Colors.tokenDark10.cgColor, Colors.tokenDark20.cgColor]
gradientLayer.opacity = 0.5
但我得到了动画:
更多努力:
我尝试使用库:,尝试从左到右链接动画,但我无法为所有子视图制作相同长度的渐变形状:
extension ShimmerExampleCell: SkeletonOwner {
var gradientLayers: [CAGradientLayer] {
return [imagePlaceholderView.gradientLayer, titlePlaceholderView.gradientLayer, subtitlePlaceholderView.gradientLayer]
}
func slide(to dir: SkeletonDirection, group: ((CAAnimationGroup) -> Void) = { _ in }) {
imagePlaceholderView.gradientLayer.slide(to: .right) { (animationGroup) in
animationGroup.beginTime = 0
}
titlePlaceholderView.gradientLayer.slide(to: .right) { (animationGroup) in
animationGroup.beginTime = 1.1
subtitlePlaceholderView.gradientLayer.add(animationGroup, forKey: CAGradientLayer.kSlidingAnimationKey)
}
}
}
我在这里得到了动画:
我用这种方法制作微光动画是错误的吗
请帮帮我!提前谢谢你 您可以尝试使用库;它应该可以帮助您在任何需要的地方轻松实现微光动画。视图控制器:
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var data: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "TableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
tableView.delegate = self
tableView.dataSource = self
for value in 0..<20 {
self.data.append("\(value) data")
self.tableView.reloadData()
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.labelName.text = data[indexPath.row]
return cell
}
UITableViewCell:我在这里设置SkeletonView的显示或隐藏状态
class TableViewCell: UITableViewCell {
@IBOutlet weak var labelName: UILabel!
@IBOutlet weak var imgView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let views = [labelName, imgView]
views.forEach {$0?.showHideSkeletonView(show: true)}
DispatchQueue.main.asyncAfter(deadline: .now()+3) {
views.forEach {$0?.showHideSkeletonView(show: false)}
}
}
ConfigSkeleton:在这里,我为skeletonView添加了一个设置、动画和颜色功能
import SkeletonView
extension UIView {
func setSkeletonView() {
self.isSkeletonable = true
}
func showHideSkeletonView(show: Bool) {
if show {
let gradient = SkeletonGradient(baseColor: UIColor.clouds)
let animation = SkeletonAnimationBuilder().makeSlidingAnimation(withDirection: .topLeftBottomRight)
self.showAnimatedGradientSkeleton(usingGradient: gradient, animation: animation)
} else {
self.hideSkeleton()
}
}
我使用了SkeletonView和这个:。但我仍然无法实现理想的动画效果。如果观看所需的动画,使用可以看到所有子视图的渐变长度是相同的。我编辑了我的问题,以提供更多我试图使用的代码。如果你有时间,请再读一遍我的问题。多谢各位