View shows up in Debug View Hierarchy, but NOT on device/sim
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.
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).
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:
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.
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...