【问题标题】:Can't see content from view controller under navigation controller在导航控制器下看不到来自视图控制器的内容
【发布时间】:2017-08-12 09:48:26
【问题描述】:

这个问题之前出现过,但公认的解决方案似乎无法解决我的问题,这就是为什么我希望另一双眼睛能发现我做错了什么。我正在尝试为 iPhone 应用程序呈现第二个导航控制器,其中背景是深色和半透明的,以便用户可以看到先前视图控制器的内容。代码如下:

-(void)viewDidLoad
{
    [super viewDidLoad];
    RootViewController *rvc = [[UIStoryboard storyboardWithName:@"RootView" bundle:nil] instantiateViewControllerWithIdentifier:@"RootViewRVC"];
    self.nvc = [[UINavigationController alloc] initWithRootViewController:rvc];
    self.nvc.modalPresentationStyle = UIModalPresentationOverCurrentContext;    
    [self presentViewController:self.nvc animated:YES completion:nil];
}

上面的代码产生了这个:

该应用目前正在为导航控制器和 rootviewcontroller 使用故事板,并显示我想要实现的目标:

TableViewController 是与两个图像中的 rootviewcontroller 关联的属性(代码使用相同的情节提要)。从导航控制器情节提要中,Xcode 8 中的属性检查器将“Presentation”设置为“Over Current Context”(而“Over Full Screen”也可以),这似乎可以解决问题,但我更喜欢以编程方式执行此操作,因此没有解决方案请使用故事板。

【问题讨论】:

  • 是的,我也看到了这个问题,但由于某种原因,接受的解决方案对我不起作用。
  • 添加定义PresentationContext 设置为YES。 stackoverflow.com/a/26891602/5184217
  • Rajesh - 您发送的链接还将modalPresentationStyle 设置为OverCurrentContext,这是我在推送导航控制器之前所做的。尝试设置definePresentationContext,但它所做的只是将第二个导航控制器的导航栏移到原来的下方;无法解决我无法解决的透明问题。
  • 试试下面的一个。 UIColor *颜色 = ...; color = [color colorWithAlphaComponent:0.5f]; [self.nvc.view setBackgroundColor:color];

标签: ios objective-c iphone uinavigationcontroller uimodalpresentationstyle


【解决方案1】:

这可能有效:

-(void)viewDidLoad
{
    [super viewDidLoad];
    RootViewController *rvc = [[UIStoryboard storyboardWithName:@"RootView" bundle:nil] instantiateViewControllerWithIdentifier:@"RootViewRVC"];
    rvc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    self.nvc = [[UINavigationController alloc] initWithRootViewController:rvc];    
    [self.nvc.view setBackgroundColor:[UIColor colorWithRed:1.0 green:0 blue:0 alpha:0.5]];
    [self presentViewController:self.nvc animated:YES completion:nil];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多