Uitableview BackgroundImageView应设置动画
我想淡入UIImageView作为UITableView的背景视图。这不是动画。图像就在那里。你知道为什么吗 这是我的密码:Uitableview BackgroundImageView应设置动画,uitableview,swift,animation,background-image,Uitableview,Swift,Animation,Background Image,我想淡入UIImageView作为UITableView的背景视图。这不是动画。图像就在那里。你知道为什么吗 这是我的密码: override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) let backgroundImage = UIImage(named: "theImage") let imageView = UIImageView() imageView.ima
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
})
}
谢谢它不起作用,因为您在视图中调用它时,它会出现在加载视图之前,因此动画不可见。 尝试将其更改为ViewDidDisplay,它将正常工作。你不需要改变
self.tableView.backgroundView?.alpha = 0.0
imageView.alpha足够了,请尝试:
override func viewDidAppear(animated: Bool)
{
super.viewDidAppear(animated)
let backgroundImage = UIImage(named: "theImage")
let imageView = UIImageView()
imageView.image = backgroundImage
imageView.contentMode = UIViewContentMode.ScaleAspectFit
self.tableView.backgroundView = imageView
imageView.alpha = 0.0
UIView.animateWithDuration(3.0, animations: { () -> Void in
imageView.alpha = 1.0
})
}
不,那不行。和以前一样的行为。当我把代码放到viewDidLoad中时,它就工作了,在这种情况下,这对我来说已经足够好了。谢谢anyway@NickSt我试过了,它确实有效。你复制并粘贴了我的代码吗?ViewDidDisplay在viewDidLoad之后启动,因此也应该在ViewDidDisplay中工作。是的,我这样做了。我甚至尝试在viewDidLoad中加载图像,并在viewDidLoad中显示动画代码。那也不管用。