介绍
- WWDC23 推出的 Symbol Animations 使得 SF Symbols 中的图标可以呈现丰富多彩的动画。
- UIImageView 通过
addSymbolEffect()
方法增加动画效果。 - WWDC24 中 Symbol Animations 新增了动画效果
rotate
、wiggle
与breathe
以及控制方式periodic
。
使用
代码语言:swift
复制import UIKit
class ViewController: UIViewController {
lazy var imageView: UIImageView = {
let imageView = UIImageView(image: UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal))
imageView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
imageView.contentMode = .scaleAspectFit
imageView.center = view.center
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
// iOS18新增
imageView.addSymbolEffect(.rotate, options: .repeat(.periodic(3, delay: 1)), animated: true) // periodic控制方式:重复执行3次,延迟1s
}
}
代码语言:swift
复制import UIKit
class ViewController: UIViewController {
lazy var imageView: UIImageView = {
let imageView = UIImageView(image: UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal))
imageView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
imageView.contentMode = .scaleAspectFit
imageView.center = view.center
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
// iOS18新增
imageView.addSymbolEffect(.wiggle, options: .repeat(.continuous), animated: true)
}
}
代码语言:swift
复制import UIKit
class ViewController: UIViewController {
lazy var imageView: UIImageView = {
let imageView = UIImageView(image: UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal))
imageView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
imageView.contentMode = .scaleAspectFit
imageView.center = view.center
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
// iOS18新增
imageView.addSymbolEffect(.breathe, options: .repeat(.continuous), animated: true)
}
}