【问题标题】:Animation fadein/fadeout title button doesn't work动画淡入/淡出标题按钮不起作用
【发布时间】:2016-02-06 11:29:11
【问题描述】:

我正在尝试为 animate UIButton 编写一个函数,按顺序执行以下几点:

  • 更改按钮文字
  • 更改按钮文字颜色
  • 使用连续淡入/淡出效果为按钮文本设置动画

所以我写了这个:

static func pulseTitleLabel(button: UIButton, text: String, color: UIColor)
{
    button.setTitle(text, forState: [.Normal, .Highlighted])
    button.setTitleColor(color, forState: [.Normal, .Highlighted])

    UIView.animateWithDuration(1.0, delay: 0.0, options: [.Repeat, .Autoreverse], animations: { () -> Void in
        button.titleLabel?.alpha = 0.0
    }, completion: nil)
}

但我看不到任何动画。

标题按钮变成了我想要的文本和颜色,但动画没有开始:我错过了什么?还有另一种更好更优雅的方式来做同样的事情吗?

【问题讨论】:

    标签: ios swift animation uiview uikit


    【解决方案1】:

    我试过你的代码,但它对我不起作用,因为我使用了系统按钮。我将按钮的类型更改为“自定义”,它现在可以工作了(如果可以的话,我会看到脉冲动画)。你能验证按钮的类型是自定义的吗?

    总的来说,您的方法已经足够好了。如果您想研究更复杂的动画(不仅仅是按钮),请查看 Facebook Pop 动画https://github.com/facebook/pop(一些示例https://github.com/hossamghareeb/Facebook-POP-Tutorial

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 2012-09-25
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      相关资源
      最近更新 更多