UIStackView - 隐藏堆栈视图时的布局约束问题 [英] UIStackView - layout constraint issues when hiding stack views

查看:1236
本文介绍了UIStackView - 隐藏堆栈视图时的布局约束问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用有两个屏幕:


  1. TableViewVC(此处没有堆栈视图)

  1. TableViewVC (no stack views here)

DetailVC(此处所有嵌套堆栈视图;请参阅图片链接:嵌套StackViews图片) - 注意,这些堆栈视图中有标签和图像。

DetailVC (all the nested stack views here; please see link for picture: Nested StackViews Picture) -- Note, there are labels and images within these stack views.

当您按下tableview中的单元格时,它会将TableViewVC中的信息传递给DetailVC。问题在于将特定的UIStackViews隐藏在DetailVC中。我希望只要视图加载,就会隐藏DetailVC中各个窗口中的2个堆栈视图。因此,我在DetailVC中编写此代码来实现此目的:

When you press a cell in the tableview, it passes the information from the TableViewVC to the DetailVC. The problem is with hiding the specific UIStackViews in the DetailVC. I want only 2 stack views out of the various ones in the DetailVC to be hidden as soon as the view loads. So I write this code in the DetailVC to accomplish this:

override func viewDidLoad() {
    super.viewDidLoad()

    self.nameLabel.text = "John"

    self.summaryStackView.hidden = true
    self.combinedStackView.hidden = true
}

一切看起来都不错,但Xcode仅在运行时时发出许多警告。应用程序未运行时,Storyboard中没有警告。请参阅错误图片链接:错误图片

Everything looks great but Xcode give many warnings only at runtime. There are no warning in Storyboard when the app is not running. Please see link for picture of errors: Picture of Errors

基本上它有很多UISV隐藏,UISV间距,UISV-canvas连接错误。如果我在 viewDidAppear 中隐藏相同的堆栈视图,这些错误就会消失,但随后会有隐藏的内容,然后隐藏它们。用户简要地看到视图然后隐藏哪个不好。

Basically it's a lot of UISV-hiding, UISV-spacing, UISV-canvas-connection errors. These errors go away if I hide the same stack views in viewDidAppear but then there is a flash of the stuff that was supposed to be hidden and then it hides. The user sees the the view briefly and then it hides which is not good.

很抱歉由于无法实际发布图片而不是链接,仍然无法发布。

Sorry for not being able to actually post pictures instead of links, still can't do so.

有关如何解决此问题的任何建议?这是我真正想要推出到应用程序商店的应用程序 - 这是我的第一个,所以任何帮助都会很棒!

Any suggestions on how to fix this? This is for an app I actually want to launch to the app store - it's my first so any help would be great!

编辑/更新1:

我找到了一个小代码,我把这个代码放在名为DetailVC的第二个屏幕中:

// Function I use to delay hiding of views
func delay(delay: Double, closure: ()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,
            Int64(delay * Double(NSEC_PER_SEC))
        ),
        dispatch_get_main_queue(), closure)
}

// Hide the 2 stack views after 0.0001 seconds of screen loading
override func awakeFromNib() {
    delay(0.001) { () -> () in
        self.summaryStackView.hidden = true
        self.combinedStackView.hidden = true
    }
}

// Update view screen elements after 0.1 seconds in viewWillAppear
override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    delay(0.1) { () -> () in
        self.nameLabel.text = "John"
    }
}

这完全消除了Xcode中关于布局约束的警告。

This gets rid of the warnings about layout constraints completely from Xcode.

它仍然不完美,因为有时我看到了应该看到的视图的一瞥被隐藏 - 它们在屏幕上快速闪烁然后消失。这种情况发生得如此之快。

It's still not perfect because sometimes I see a glimpse of the views that are supposed to be hidden -- they flash really quick on the screen then disappear. This happens so quickly though.

有关为什么要摆脱警告的任何建议?此外,任何关于如何改善这个完美工作的建议???谢谢!

Any suggestions as to why this gets rid of warnings? Also, any suggestions on how to improve this to work perfectly??? Thanks!

推荐答案

您是否尝试过此操作,在更改后调用超级?

Have you tried this, calling the super after your changes?

override func viewWillAppear() {

    self.nameLabel.text = "John"

    self.summaryStackView.hidden = true
    self.combinedStackView.hidden = true

    super.viewWillAppear()
}

这篇关于UIStackView - 隐藏堆栈视图时的布局约束问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆