[英]Presenting a modal ViewController which has semi transparent background
我在SecondViewController
模态显示FirstViewController
,并且SecondViewController
具有半透明的背景(白色,不透明度为70%)。
我现在面临的问题是,当我提出SecondViewController
,认为FirstViewController
直至仍然可见SecondViewController
已完成呈现。
这使UI看起来很滞后。 我期待的行为一旦SecondViewController
提出,该视图FirstViewController
应该是不可见的,或观才逐渐淡出SecondViewController
出现。
任何帮助将不胜感激!
我用于演示的代码是:
SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:@“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
[self presentViewController:cntrlr animated:YES completion:nil];
SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:@“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
self.view.alpha = 0.0f;
[self.navigationController.navigationBar setHidden:YES];
[self presentViewController:cntrlr animated:YES completion:nil];
// Need to set FirstViewController alpha 1.0f after dismisViewControlle
r // Need to set FirstViewController alpha 1.0f after dismisViewControlle
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.view.alpha = 1.0f;
[self.navigationController.navigationBar setHidden:NO];
}
在iOS 3.2之后,有一种方法可以执行此操作而没有任何“技巧” –请参阅modalPresentationStyle属性的文档。 您有一个rootViewController,它将显示viewController。 因此,这是成功的代码:
viewController.view.backgroundColor = [UIColor clearColor];
rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[rootViewController presentModalViewController:viewController animated:YES];
使用此方法,viewController的背景将是透明的,而底层的rootViewController将是可见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.