UIView.animateWithDuration不在单独的视图控制器

时间:2016-06-28 07:15:42

标签: ios swift uiviewanimation

将动画设置为反复淡入淡出。 'viewSmall'和'viewBig'是UIImageViews。

view storyboard shot

class TestViewController: UIViewController {

    @IBOutlet weak var viewBig: UIImageView!
    @IBOutlet weak var viewSmall: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        animate()
    }

    func animate() {
        UIView.animateWithDuration(0.5,
                                   delay: 0,
                                   options: [.Repeat, .Autoreverse],
                                   animations: {
                                    self.viewSmall.alpha = 0
            },
                                   completion: nil)

        UIView.animateWithDuration(0.5,
                                   delay: 0,
                                   options: [.Repeat, .Autoreverse],
                                   animations: {
                                    self.viewBig.alpha = 0
            },
                                   completion: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

根据我的猜测,此代码不会在少数几个视图控制器上制作动画,并且视图控制器看起来是独立的,对其他视图控制器没有任何影响。因为此代码在连接到导航视图控制器的视图控制器上运行良好。

如何在独立视图控制器上创建它? 请帮忙。

1 个答案:

答案 0 :(得分:0)

找到了一个出色的解决方案。 使用dispatch_after捕获持续时间和延迟。

Settings > Cloud Messaging > Server key

来自: Swift UIView animateWithDuration completion closure called immediately