简体   繁体   English

如何修复ios15中丢失的淡入淡出动画CATransition?

[英]How to fix missing fade animation CATransition in ios15?

I have a bottom-up push animation of text.我有一个自下而上的文本推送动画。 In iOS 14 and earlier, she worked with fade animation.在 iOS 14 及更早版本中,她使用淡入淡出动画。 Starting with iOS 15, the behavior has changed: the implicit fade disappeared.从 iOS 15 开始,行为发生了变化:隐式淡入淡出消失了。 Any ideas on how to get it back?关于如何取回它的任何想法?

It is necessary for the new layer to enter with opacity 0 to 1, and the old layer to go into opacity 0.需要新图层进入不透明度为0到1,旧图层进入不透明度为0。

let pushAnimation: CATransition = {
  let animation = CATransition()
  animation.timingFunction = CAMediaTimingFunction(name: .easeIn)
  animation.type = .push
  animation.subtype = .fromTop
  animation.duration = 0.5
  return animation
}()
...

label.layer.add(pushAnimation, forKey: nil)
label.text = newText

You're perfectly correct that this behavior has changed in iOS 15. You might want to file a bug report with Apple.您完全正确地认为这种行为在 iOS 15 中发生了变化。您可能想向 Apple 提交错误报告。 The implicit opacity change, however, was arguably always wrong, so they might reply that this now works as expected.然而,隐含的不透明度变化可以说总是错误的,所以他们可能会回答说这现在按预期工作。

A minimal solution here might be to add a fade animation to your transition:这里的最小解决方案可能是为您的过渡添加淡入淡出动画:

    let ba = CABasicAnimation(keyPath: #keyPath(CALayer.opacity))
    ba.duration = 0.5
    ba.fromValue = 0
    label.layer.add(ba, forKey: nil)

The fact is, however, that CATransition is extremely simple-minded, and if you want animation you can control, you should be using real animation.然而,事实是,CATransition 是极其简单的,如果你想要你可以控制的动画,你应该使用真正的动画。 View transition animation, for example, will allow you replace one view with another while animating it in any way you wish, with full control over position animation, alpha animation and so forth.例如,视图转换动画将允许您在以任何您希望的方式对其进行动画处理的同时将一个视图替换为另一个视图,并完全控制位置动画、alpha 动画等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM