xcode 视图显示在调试视图层次结构中,但不在设备/sim 上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29471946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:55:29  来源:igfitidea点击:

View shows up in Debug View Hierarchy, but NOT on device/sim

iosiphonexcodeviewuiview

提问by Kyle Bashour

This issue is seriously perplexing me. I have a small UIView I'm using to show which button is selected. However, it's not showing up in my app —?it should be under "Local Activities," but doesn't show up:

这个问题严重困扰着我。我有一个小的 UIView 用于显示选择了哪个按钮。但是,它没有出现在我的应用程序中——它应该在“本地活动”下,但没有出现:

Image

图片

That's fine, I thought, I'll just debug the view hierarchy and see where it is! And it looks like it's exactly where it should be:

没关系,我想,我只是调试视图层次结构,看看它在哪里!看起来它正是它应该在的地方:

View Hierarchy3D View —?it's on top of everything!

查看层次结构3D 视图——它在一切之上!

Does anyone know what might be going on here? Thanks for the help!

有谁知道这里会发生什么?谢谢您的帮助!

采纳答案by Kyle Bashour

I'm stupid — I fixed it. I'm not sure why it shows up as on top in the view debugger, but it was behind another UIView.

我很笨——我修好了。我不确定为什么它在视图调试器中显示为顶部,但它位于另一个 UIView 之后。

回答by WongWray

I have found what was causing this.

我已经找到了导致这种情况的原因。

I programmatically created two subviews (Subview A and Subview B) inside a view controller; neither of which appeared on my device even though the frames' size and positions, alpha values, and all the other usual visibility issues all checked out. Subview A was a subview of the view controller's view, and Subview B was a subview of Subview A. Neither were visible on my device, but when I looked in the View Debugger Hierarchy I was able to see Subview B (even though its superview, Subview A, was not visible).

我在视图控制器中以编程方式创建了两个子视图(子视图 A 和子视图 B);即使帧的大小和位置、alpha 值以及所有其他常见的可见性问题都已检查,但这些都没有出现在我的设备上。子视图 A 是视图控制器视图的子视图,子视图 B 是子视图 A 的子视图。在我的设备上两者都不可见,但是当我查看视图调试器层次结构时,我能够看到子视图 B(即使它的超级视图,子视图 A,不可见)。

Long story short, the issue was fixed when I removed code that was altering Subview A's layer's mask property. Here's the exact method that was being called on the layer:

长话短说,当我删除改变子视图 A 图层蒙版属性的代码时,问题得到了解决。这是在图层上调用的确切方法:

extension CALayer {
    func round(corners: UIRectCorner, withRadius radius: CGFloat, withBounds: CGRect? = nil) {
        let path = UIBezierPath(roundedRect: withBounds ?? bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
        let mask = CAShapeLayer()
        mask.path = path.cgPath
        self.mask = mask
    }
}

I've used this method in the past with no issues so I'm sure the problem was somewhat circumstantial but maybe this will point someone in the right direction in the future.

我过去使用过这种方法没有任何问题,所以我确定这个问题在某种程度上是偶然的,但也许这会在未来指明某人正确的方向。

Edit

编辑

The issue wasn't just the code shown above but the fact that I was changing Subview A's frame after calling round(). Once I made sure to only round() Subview A after it had been given its final position and size, all issues with both device and debugger were solved.

问题不仅在于上面显示的代码,还在于我在调用 round() 后更改了子视图 A 的框架。一旦我确定在给定最终位置和大小后只对子视图 A 进行 round() 处理,设备和调试器的所有问题都解决了。

回答by David T

I had this same problem in Xcode 9. The cause for me was that I had set the alpha of the view to 0 in viewDidLoad, but did not set the alpha back to 1.0. For some reason the Debug View Hierarchy showed it with an alpha of 1.0...

我在 Xcode 9 中遇到了同样的问题。我的原因是我在 viewDidLoad 中将视图的 alpha 设置为 0,但没有将 alpha 设置回 1.0。出于某种原因,调试视图层次结构显示它的 alpha 值为 1.0 ...

回答by bdelliott

I had the same problem but when I rewired my outlets, it started working again.

我遇到了同样的问题,但是当我重新连接插座时,它又开始工作了。