BackgroundImageView应该是Animate

时间:2015-05-30 14:18:46

标签: uitableview swift animation background-image

我希望将UIImageView作为UITableView的BackgroundView淡入淡出。它不是动画。图像就在那里。有什么想法吗?

这是我的代码:

override func viewWillAppear(animated: Bool)
{
    super.viewWillAppear(animated)

    let backgroundImage = UIImage(named: "theImage")
    let imageView = UIImageView()
    imageView.image = backgroundImage
    imageView.contentMode = UIViewContentMode.ScaleAspectFit
    self.tableView.backgroundView = imageView

    //Tried it this way
    imageView.alpha = 0.0

    //and that way
    self.tableView.backgroundView?.alpha = 0.0

    UIView.animateWithDuration(3.0, animations: { () -> Void in
        //Both not animating
        self.tableView.backgroundView?.alpha = 1.0
        imageView.alpha = 1.0
    })
}

由于

1 个答案:

答案 0 :(得分:0)

它不起作用,因为你在this.props.children中调用它,它在视图加载之前发生,因此动画是不可见的。 尝试将其更改为viewWillAppear,它会起作用。您无需更改

viewDidAppear

self.tableView.backgroundView?.alpha = 0.0 就足够了,试试看:

imageView.alpha