。重复.AutoReverse不工作

时间:2016-01-31 14:16:09

标签: ios swift uiviewanimation animatewithduration

我在点击按钮时使用动画转换按钮,我可以让按钮更大。但是,我认为通过使用.Repeat和.Autoreverse,按钮将返回其正常状态。 (规模1.0)但事实并非如此!也许我误解了我读到的有关.AnimateWithDuration ??

的教程和问题

这是我正在使用的代码:

 let button = sender as! UIButton

    UIView.animateWithDuration(1.0, delay: 0.6,
        options: [.Repeat, .Autoreverse, .AllowUserInteraction],
        animations:{
        button.transform = CGAffineTransformMakeScale(1.2, 1.2)
        }, completion: nil)

在另一个问题中,我看到可以通过添加.AllowUserInteraction来解决问题,但事实并非如此。

我不知道它是否重要,但此代码包含在触摸事件中。

 @IBAction func addButtonClicked(sender: AnyObject) {}

这可能会发生什么?这不是你应该如何扭转动画吗?

1 个答案:

答案 0 :(得分:1)

在动画结束时,您应该重置对象的大小 .Autoreverse只是“在视觉上反转”,但不会改变实际的对象大小。

试试这个。

@IBAction func prss(sender: AnyObject) {

    let btt = sender as! UIButton

    UIView.animateWithDuration(1.0, delay: 0.6,
        options: [.Autoreverse, .AllowUserInteraction],
        animations:{
            btt.transform = CGAffineTransformMakeScale(5.0, 5.0)
        }, completion: { (t) -> Void in
            btt.transform = CGAffineTransformMakeScale(1.0, 1.0)
    })

}