gpt4 book ai didi

ios - UISwitch 在动画 'onTintColor' 时中断开/关动画

转载 作者:行者123 更新时间:2023-11-28 19:30:48 25 4
gpt4 key购买 nike

我想为 UISwitch 的“开启”颜色设置动画并使其保持可交互性,同时不影响其开启/关闭动画。这是我尝试过的:

  1. UIView 的 animate with duration 方法不起作用,因为...不应该,'onTintColor' 没有列为的动画属性用户界面 View 。很好。

    mySwitch.onTintColor = UIColor.green

    UIView.animate(withDuration: 10) {
    mySwitch.onTintColor = UIColor.red
    }
  2. 下一步。 UIView 的 transition with view 方法提供了某种正确的视觉行为,但是当与开关交互时,默认的开/关动画会受到影响(参见 GIF)。

    UIView.transition(with: mySwitch, duration: 10, options: [.transitionCrossDissolve, .allowUserInteraction], animations: { 
    mySwitch.onTintColor = UIColor.red
    }) { completed in
    }
  3. CATransition 给出与 no 相同的行为。 2(参见 GIF)。

    var transition = CATransition()
    transition.type = kCATransitionFade
    transition.duration = 10
    mySwitch.layer.add(transition, forKey: kCATransition)
    mySwitch.onTintColor = UIColor.red

via GIPHY

有人知道如何在不影响默认开/关动画的情况下为“onTintColor”设置动画吗?

正确执行此操作的唯一方法是创建自定义开关吗?

最佳答案

默认情况下,用户交互在动画期间被禁用。尝试使用更长形式的 UIView 动画,

animate(withDuration:delay:options:animations:completion:),并传入.allowUserInteraction的options

关于ios - UISwitch 在动画 'onTintColor' 时中断开/关动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45002097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com