iOS模態出一個半透明的ViewControlle

    UIViewController * vc = [[UIViewController alloc]init];
    // 在present一個viewController時會需要一個提供背景的viewController,設置definespresentationcontext爲true可以把當前的viewController設置爲present的背景,present時會從當前容器中找presentationcontext,沒有找到就默認爲當前容器的rootViewController。
    vc.definesPresentationContext = YES; 
    vc.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4];
    /*
    UIModalPresentationFullScreen代表彈出VC時,presented VC充滿全屏,如果彈出VC的wantsFullScreenLayout設置爲YES的,則會填充到狀態欄下邊,否則不會填充到狀態欄之下。

    UIModalPresentationPageSheet代表彈出是彈出VC時,presented VC的高度和當前屏幕高度相同,寬度和豎屏模式下屏幕寬度相同,剩餘未覆蓋區域將會變暗並阻止用戶點擊,這種彈出模式下,豎屏時跟UIModalPresentationFullScreen的效果一樣,橫屏時候兩邊則會留下變暗的區域。

   UIModalPresentationFormSheet這種模式下,presented VC的高度和寬度均會小於屏幕尺寸,presented VC居中顯示,四周留下變暗區域。

   UIModalPresentationCurrentContext這種模式下,presented VC的彈出方式和presenting VC的父VC的方式相同。

    */ 

    vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    [self presentViewController:vc animated:YES completion:nil];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章