动画按钮。重复使@IBAction不起作用

时间:2015-12-12 10:31:23

标签: ios swift animation uiview

当我使用重复和自动反转选项为按钮设置动画时,@IBAction无效。

动画代码:

UIView.animateWithDuration(0.5, delay: 0.4, options: [.Repeat, .Autoreverse], animations: {
  self.Button.frame = CGRect(x: 80, y: 80, width: 50, height: 50)
}, completion: nil)

行动代码:

@IBAction func BtnAction(sender: UIButton) {
   Label.text = "Button pressed"
}

1 个答案:

答案 0 :(得分:0)

如@Shripada所述,我必须在选项参数中添加.allowUserInteraction

UIView.animateWithDuration(0.5, delay: 0.4, options: [.repeat, .autoreverse, .allowUserInteraction], animations: {
    self.button.frame = CGRect(x: 80, y: 80, width: 50, height: 50)
}, completion: nil)