gpt4 book ai didi

ios - viewDidAppear 中的调用未在添加约束的情况下调用

转载 作者:行者123 更新时间:2023-11-28 16:01:19 30 4
gpt4 key购买 nike

在我的代码中,我有一个 viewWillAppear 调用,类似于下面的调用,旨在将某些对象移开。

override func viewWillAppear(_ animated: Bool) {
playButton.center.x -= view.bounds.width
howToButton.center.x -= view.bounds.width
imageView1.center.x = view.bounds.width - (imageView1.frame.width / 2)
imageView2.center.x = view.bounds.width - (imageView2.frame.width / 2)
imageView1.center.x += imageView1.frame.width
imageView2.center.x += imageView2.frame.width
introductoryLabel.alpha = 0
}

这之后是一个 viewDidAppear 调用,它将这些对象动画化到场景中。我的问题是 viewDidAppear 执行动画(基本上反转 viewWillAppear 中的内容),就好像 viewWillAppear 没有被调用一样。有趣的是,这只是我在 Storyboard 中应用约束时的一个问题。我怎样才能保持约束但允许 viewDidAppear 做它的事情?

任何帮助将不胜感激!

最佳答案

Interestingly this is only a problem when I apply constraints in the storyboard

这一点也不奇怪。如果应用了约束,则不能更改 View 的中心。好吧,你可以,但这样做是没有用的,因为约束将继续根据约束重新定位它们。这毕竟是约束的目的!

所以,基本上,有两种定位事物的方法:一方面使用它们的 framecenter,另一方面使用约束。不要试图将它们混合在一起。使用其中之一。

关于ios - viewDidAppear 中的调用未在添加约束的情况下调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41030335/

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