0
votes

I'm trying to present an opaque UIViewController from a UINavigationController. While the view is being animated, it is opaque just how I want it. When it is done animating, however, the background turns gray. I had this working when the previous view was a UIViewController. When I used a UINavigationController as the previous view I started having this issue.

Code to switch to view:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:STORYBOARD_IPHONE bundle:nil];
UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:viewName];
[self presentViewController:viewController animated:YES completion:nil];

Code to make presented view opaque:

self.view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];

I think this might have something to do with the fact that the class that is presenting the view is not the UINavigationController, but a UIViewController within the UINavigationController. So I tried using self.navigationController presentViewController, but I got the same result.

How can I fix this so that the background remains opaque?

The previous UINavigationController with embedded UIViewController:

enter image description here

What it looks like during animation:

enter image description here

What it looks like after animation:

enter image description here

1
where you writing your background color code . is it in viewdidload? if it is then try to set backgoundcolor in viewwillappear.KDeogharkar
Yes, I was setting that in viewDidLoad. I tried setting it in viewWillAppear, and viewDidAppear. I have the same problem.Jared Price
You're setting your view to alpha 0.7 and wondering why you can see through it? What's behind your view - probably a black background? That and the 70% white is probably causing your gray.Owen Hartnett
@OwenHartnett It must be a black background, but why is it a black background? Why does it not show the UINavigationController behind it like it was when it was a UIViewController?Jared Price
Does the UINavigationController have a view that has a white background behind it? Or is that area transparent, and you're looking at the UIwindow behind it, which might have a black background? Are you setting a rootviewController, or just calling init in the UINavigationController?Owen Hartnett

1 Answers

0
votes

Here's a routine I use regularly to see which views are sitting behind the view I'm interested in:

// useful debugging method - send it a view and it will log all subviews
// can be called from the debugger
- (void) viewAllSubviews:(UIView *) topView Indent:(NSString *) indent  {
    for (UIView * theView in [topView subviews]){
        NSLog(@"%@%@", indent, theView);
        if ([theView subviews] != nil)
            [self viewAllSubviews:theView Indent: [NSString stringWithFormat:@"%@ ",indent]];
    }
}

I usually put it somewhere where I can access it globally. Call it like

[self viewAllSubviews:rootViewController.view Indent:@"  "];

It will print to the console the view tree rooted on whatever view you give it, and indent the subview according to level. It should reveal just what you have behind your object of interest, and you can check frame coordinates for every view there.

This should give you a good clue as to what view is behind.