在iOS 7的另一个ViewController上显示清晰的彩色ViewController

在iOS 7之前,根据这个stream行的Stackoverflow 问题,显示具有清晰背景的ViewController的方法是在主ViewController中执行以下操作:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; vc.view.backgroundColor = [UIColor clearColor]; self.modalPresentationStyle = UIModalPresentationCurrentContext; [self presentViewController:vc animated:NO completion:nil]; 

但是,正如我最近在iOS 7中发现的(以及其他人对主要答案的评论),上述解决scheme不再有效,而只是显示一个黑色的模型控制器。 我知道透明度主要在iOS 7中使用,所以透明视图控制器很可能是可能的。 我还没有发现这个问题的解决方法,并想知道是否有人知道如何解决这个问题。 谢谢!

我只是遵循原来的解决scheme,并在Interface Builder中应用了一些默认和自定义设置,在我看来,它正在工作。

  • 你可以在这里查看: https : //github.com/codedad/SO_IOS_viewcl_on_viewcl

重要的部分(非常类似于问题的代码):

 - (IBAction)click:(id)sender { NSLog(@"click"); UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"TopOverVc"]; vc.view.backgroundColor = [UIColor clearColor]; self.modalPresentationStyle = UIModalPresentationCurrentContext; [self presentViewController:vc animated:NO completion:nil]; } 
  • 也请findIB快照: 在这里输入图像说明

  • 模拟器的结果(按下button之后):

在这里输入图像说明

希望我没有误解你的问题;)快乐的编码!

对于iOS 7,子类SecondViewController并尝试在SecondViewController的viewDidLoad中设置视图背景颜色

  self.view.backgroundColor = [UIColor clearColor]; 

为什么不使用这个

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; self.modalPresentationStyle = UIModalPresentationCurrentContext; [self presentViewController:vc animated:NO completion:nil]; vc.view.backgroundColor = [UIColor clearColor]; 

尝试在视图加载后更改视图的BG颜色。 在你的第一个改变视图和呈现。 View Life循环不会以这种方式进行