Ios 我将如何编写UIView淡入动画以将SubViewToFront带到屏幕上
我正在尝试将UIView动画/淡入效果添加到我的函数:Ios 我将如何编写UIView淡入动画以将SubViewToFront带到屏幕上,ios,swift,uiview,uiviewanimation,xcode10,Ios,Swift,Uiview,Uiviewanimation,Xcode10,我正在尝试将UIView动画/淡入效果添加到我的函数: self.view.bringSubview(toFront:self.webView) 我尝试过以编程方式实现它,但UIView没有动画;相反,它只是立即显示,没有淡入效果: UIView.animate(withDuration: 1, animations: { self.view.bringSubview(toFront: self.webView) }, completion: nil)
self.view.bringSubview(toFront:self.webView)
我尝试过以编程方式实现它,但UIView没有动画;相反,它只是立即显示,没有淡入效果:
UIView.animate(withDuration: 1, animations: {
self.view.bringSubview(toFront: self.webView)
}, completion: nil)
如何为
bringSubview(:)
和sendSubview(:)
函数实现动画?我试着到处找,但似乎没有人找到答案。你不能使用UIView。像那样设置动画。它只对某些属性有效。在这种情况下,需要设置alpha
属性的动画
开始设置动画之前,请将视图的alpha
设置为0,然后将其置于前面:
self.webView.alpha = 0
self.view.bringSubview(toFront: self.webView)
// After that you animate the alpha:
UIView.animate(withDuration: 1, animations: {
self.webView.alpha = 1
}, completion: nil)