【问题标题】:How to flash/change a UIButton borderColor with animation如何使用动画闪烁/更改 UIButton 边框颜色
【发布时间】:2016-01-06 06:33:11
【问题描述】:

我有 UIButton,我想向它添加一个连续闪烁/更改边框颜色动画。所以它应该从没有边框颜色开始,然后在 1 秒后变为绿色,然后重复。

我该怎么做?

【问题讨论】:

    标签: ios swift animation uibutton


    【解决方案1】:

    希望对你有帮助

        targetButton.layer.borderWidth = 8.0
        let color: CABasicAnimation = CABasicAnimation(keyPath: "borderColor")
        color.fromValue = UIColor.clearColor().CGColor
        color.toValue = UIColor.greenColor().CGColor
        color.duration = 0.5
        color.autoreverses = true
        self.targetButton.layer.borderColor = UIColor.clearColor().CGColor
        self.targetButton.layer.addAnimation(color, forKey: "")
    

    抱歉,我忘了设置按钮边框宽度。 你可以再试一次。

    【讨论】:

    • 请再试一次并告诉我结果。
    • 它可以工作,但不平滑,当颜色设置为蓝色时,它会变回clearColor,但没有淡入淡出动画......
    • 再试一次。我添加了新行 color。自动反转 = 真
    猜你喜欢
    • 1970-01-01
    • 2015-06-22
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多