简体   繁体   中英

iOS opaque UIViewController on top of UINavigationController

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:

在此处输入图片说明

What it looks like during animation:

在此处输入图片说明

What it looks like after animation:

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM