我希望用户通过单击UIBarButtonItem来更改全局tintColor。我的代码是:
@IBAction func changeColor(_ sender: UIBarButtonItem) {
UserDefaults.standard.set(!UserDefaults.standard.bool(forKey: "orangeTint"), forKey: "orangeTint")
UIView.animate(withDuration: 0.5, delay: 0, options: [.beginFromCurrentState , .transitionCrossDissolve], animations: {
self.view.window?.tintColor = UserDefaults.standard.bool(forKey: "orangeTint") ? .systemBlue : .systemOrange
})
}
当我对此进行测试时,除了UIBarButtonItems之外,所有内容都随着动画改变了tintColor。他们没有动画。观看视频:https://imgur.com/a/X2gB7Ik