gpt4 book ai didi

swift - 淡入链动画不起作用 : only view fades in

转载 作者:行者123 更新时间:2023-11-30 10:42:00 25 4
gpt4 key购买 nike

我正在尝试使用动画链中的淡入淡出来按顺序淡入我的对象。首先,我使 View 淡入,然后其余标签也应效仿。标签位于堆栈 View 中,其 alpha 为 1.0。我确保所有其他 alpha 值都从零开始。这是我的功能:

func fadeIn() {
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.view.alpha = 1.0
}, completion: { finished in
if finished {
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.gameOverLabel.alpha = 1.0
}, completion: { finished in
if finished {
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.scoreLabel.alpha = 1.0
}, completion: { finished in
if finished {
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.highScoreLabel.alpha = 1.0
}, completion: { finished in
if finished {
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.restartButton.alpha = 1.0
}, completion: nil)
//breakpoint set here
}
})
}
})
}
})
}
})
}

我在所有动画完成后设置了一个断点(如上所示)并且所有 alpha 值为 1.0。然而,该设备只给我一个空白的白色屏幕。这是怎么回事?

附注该函数在 View Controller 出现后立即调用:

view.present(vc, animated: false, completion: {
vc.fadeIn()
})

最佳答案

尝试将 .layoutSubviews 选项添加到您的动画中。像这样:

UIView.animate(withDuration: 1.0, delay: 0.0, options: UIView.AnimationOptions.layoutSubviews, animations: {
// animate here
})

根据苹果的文档,此选项的作用是:

Lay out subviews at commit time so that they are animated along with their parent.

可能由于已呈现, subview 在提交时尚未布局。

关于swift - 淡入链动画不起作用 : only view fades in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56589506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com