UIImageView
- 支持显示 HDR 图片。
import UIKit
class ViewController: UIViewController {
lazy var imageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "hdr.png"))
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
imageView.contentMode = .scaleAspectFit
imageView.center = view.center
// 支持HDR图片
imageView.preferredImageDynamicRange = .constrainedHigh
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
}
}
- Symbol Animations 新特性使得 SF Symbols 中的图标可以呈现丰富多彩的动画。通过
addSymbolEffect()
方法增加动画效果,removeSymbolEffect()
与removeAllSymbolEffects()
方法移除动画效果。
import UIKit
class ViewController: UIViewController {
lazy var imageView: UIImageView = {
let imageView = UIImageView(image: UIImage(systemName: "touchid"))
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
imageView.contentMode = .scaleAspectFit
imageView.center = view.center
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
imageView.addSymbolEffect(.variableColor.reversing, options: .repeat(3), animated: true) { context in
if context.isFinished {
print("动画完成")
}
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
imageView.removeSymbolEffect(ofType: .variableColor.reversing)
// imageView.removeAllSymbolEffects()
}
}
UIButton
Symbol Animations 新特性使得按钮中使用的 SF Symbols 图标也可以呈现动画。
import UIKit
class ViewController: UIViewController {
lazy var button1: UIButton = {
let button = UIButton(frame: CGRect(x: 100, y: 0, width: 100, height: 60))
button.setImage(UIImage(systemName: "heart"), for: .normal)
// 开启Symbol Animations
button.isSymbolAnimationEnabled = true
return button
}()
lazy var button2: UIButton = {
let actionHandler = UIAction { _ in
}
actionHandler.image = UIImage(systemName: "plus")
let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 60), primaryAction: actionHandler)
button.isSymbolAnimationEnabled = true
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(button1)
view.addSubview(button2)
}
}
网友评论