在iOS 7之前,根据这个流行的Stackoverflow question,,显示具有清晰背景的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中发现的那样(以及其他人对主要答案的评论),上述解决方案不再有效,而只是显示了黑色模型控制器。我知道透明度主要用于iOS 7,因此透明视图控制器很有可能。我还没有发现这个问题的解决方法,并且想知道是否有人知道如何解决这个问题。谢谢!
答案 0 :(得分:8)
我只是按照原始解决方案并在Interface Builder中应用了一些默认和自定义设置,在我看来它正在工作。
重要部分(与问题代码非常相似):
- (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];
}
同时请找到IB snaphot:
模拟器结果(按下按钮后):
希望我没有误解你的问题;)快乐的编码!
答案 1 :(得分:-2)
对于iOS 7,继承SecondViewController并尝试在SecondViewController的viewDidLoad中设置视图背景颜色
self.view.backgroundColor = [UIColor clearColor];
答案 2 :(得分:-3)
为什么不使用这个
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颜色。 在你的解决方案中首先改变视图和呈现。视图生命周期不会以这种方式进行