34

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 Hierarchy 3D View — it's on top of everything!

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

Kyle Bashour
  • 1,327
  • 2
  • 13
  • 20
  • What exactly you expect to see on your device? – Mike.R Apr 06 '15 at 13:12
  • Whats the background color of your button, may be your button overrides the view you want to show as selected. And also describe how you are highlighting the UIView. – Samir Apr 06 '15 at 13:15
  • The background is UIColor.clearColor(), and it's hard to tell from my screenshot, but in the 3D view, it's definitely on top of the Activities Button. Mike — I expect to see the white line under the activities button, which you can see in the view debug hierarchy, but not on the running app. – Kyle Bashour Apr 06 '15 at 13:25
  • 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. – Kyle Bashour Apr 06 '15 at 13:30
  • 1
    For me it turned out `alpha` was set to `0` in "User Defined Runtime Attributes"... – Koen. Aug 27 '18 at 13:14

5 Answers5

37

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
WongWray
  • 2,414
  • 1
  • 20
  • 25
13

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.

Kyle Bashour
  • 1,327
  • 2
  • 13
  • 20
  • 4
    I had this happen and i had reused code in a transition that had set my views alpha to 0 lol. – NSGangster May 24 '16 at 18:23
  • I have the same issue. Tried all the things.. Like make alpha 1, hidden property set to false, bring to front of all other view by [[UIApplication sharedApplication].keyWindow bringSubviewToFront:yourSubview]. Please suggest me some other solution if anyone find it. – NSP Sep 22 '16 at 12:33
  • @KyleBashour: How did you find that out? –  Feb 13 '17 at 20:37
  • @NSGangster Wow, that's exactly the problem that I had. Thanks for bringing that up. It's definitely notable that zero-alpha stuff shows up in the view debugger, but not in the app. – Matt Mc Mar 05 '18 at 03:36
  • How did you bring your view forward? – regina_fallangi Oct 16 '18 at 07:42
9

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...

David T
  • 2,724
  • 1
  • 17
  • 27
  • 2
    Same here. For me, there are animations for the screen that set alpha to 0, which will make the view show in view debugger but not in device. – somenickname Jun 27 '18 at 01:53
0

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

bdelliott
  • 463
  • 1
  • 7
  • 12
0

in my case, the invisible view A has a parent view B, and some one set layer.mask to B

CAGradientLayer *layer = [CAGradientLayer layer];
CGFloat ratio = 0.05;

layer.frame = CGRectMake(0, 0, kScreenWidth, B.height);
layer.colors = @[(__bridge id)[[UIColor blackColor] colorWithAlphaComponent:0.0].CGColor, (__bridge id)[UIColor blackColor].CGColor];
layer.locations = @[@0, @(ratio), @1];

B.layer.mask = layer

But B.height is equal to 0 at this time, so I put these code in layoutSubviews to execute, and it becomes visible.

nenseso
  • 33
  • 5