Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

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!

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

like image 314
Kyle Bashour Avatar asked Apr 06 '15 13:04

Kyle Bashour


1 Answers

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.

like image 109
WongWray Avatar answered Sep 17 '22 12:09

WongWray