swift - UIView.animateWithDuration 没有动画

标签 swift ios8 animatewithduration xcode6.0.1

我的 ViewController viewDidLoad 函数中的 UIView.animateWithDuration 调用没有动画。立即调用完成 block 。 println 输出显示“完成为真”。 viewDidLoad 函数是否放错了我的启动动画?非常感谢任何提示。

class ViewController: UIViewController {
    @IBOutlet var beatIndicator:UIView?

    override func viewDidLoad() {
        super.viewDidLoad()

        if let led = beatIndicator? {
            led.alpha = 1.0
            led.frame = CGRectMake(20, 20, 30, 30)
            led.layer.cornerRadius = 15

            UIView.animateWithDuration(3.0, animations:{
                led.alpha = 0.5
                led.frame = CGRectMake(25, 25, 20, 20)
                led.layer.cornerRadius = 10
            }, completion:{(value: Bool) in
                println("completion \(value)")
            })
        }

        // ...
    }
}

最佳答案

你试过把它放在 ViewDidAppear 中吗?

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    if let led = beatIndicator {
        led.alpha = 1.0
        led.frame = CGRect(x: 20, y: 20, width: 30, height: 30)
        led.layer.cornerRadius = 15

        UIView.animate(withDuration: 3.0, animations:{
            led.alpha = 0.5
            led.frame = CGRect(x: 25, y: 25, width: 20, height: 20)
            led.layer.cornerRadius = 10
        }, completion:{(value: Bool) in
            print("completion \(value)")
        })
    }

    // ...
}

关于swift - UIView.animateWithDuration 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26118141/

相关文章:

ios - Swift UIView 框架未在 animateWithDuration 内正确更新

ios - 从另一个 UITableViewCell 类隐藏自定义 UITableViewCell

ios - 谷歌地图上的透明 UIView - Swift

ios - 在 iOS 7 手机上使用 iOS 8 功能,hidesBarsOnSwipe

ios - iOS8分享扩展获取视频属性的方法

ios - 如何将弹跳动画添加到 animateWithDuration?

ios - .Repeat .AutoReverse 不起作用

Android LayoutInflation 的 iOS/Swift 等价物

objective-c - Objective C 到 Swift 的调度过程

ios - Swift 中的小数