[英]Present a ViewController although UIAlertController is in the view Hierarchy
[英]Can we present a translucence ViewController like UIAlertController?
我想像UIAlertController一樣封裝一個半透明的ViewController,命名為CQAlertController。在CQAlertController的viewDidLoad
方法中,我編寫了:
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
但是當我在rootViewController中使用當前的CQAlertController時:
CQAlertController *alertController = [CQAlertController alertControllerWithTitle:@"title" message:@"detail" preferredStyle:CQAlertControllerStyleActionSheet];
[self presentViewController:alertController animated:YES completion:nil];
它沒有呈現半透明的ViewController,而是一個全黑的ViewController。
有什么辦法可以呈現半透明的ViewController嗎?
注意:
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
方法已棄用,因此我根本不想使用此方法。
我想要得到的目標是使用方法presentViewController:animated:
像呈現UIAlertController一樣直接呈現半透明ViewController 。
我應該為CQAlertController做些什么?
嘗試這個:
CQAlertController *alertController = [CQAlertController alertControllerWithTitle:@"title" message:@"detail" preferredStyle:CQAlertControllerStyleActionSheet];
alertController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:alertController animated:YES completion:nil];
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.