UIView.animateWithDuration没有动画 [英] UIView.animateWithDuration not animating

查看:350
本文介绍了UIView.animateWithDuration没有动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ViewController viewDidLoad函数中的UIView.animateWithDuration调用没有动画。立即调用完成块。 println输出显示'completion true'。 viewDidLoad函数是否放置了我的启动动画的错误位置?非常感谢任何提示。

The UIView.animateWithDuration call in my ViewController viewDidLoad function does not animate. The completion block gets called immediately. The println output shows 'completion true'. Is the viewDidLoad function the wrong place to put my startup animation? Any hints are greatly appreciated.

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?

Have you tried putting it in ViewDidAppear?

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        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)")
            })
        }

        // ...
    }

这篇关于UIView.animateWithDuration没有动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆