2016-08-16 80 views
0

我想創建一個具有透明背景的模式視圖控制器,但是當我嘗試將背景的alpha設置爲0.5時,它只是將背後的視圖變爲完全黑色。這是因爲在轉換後,背景視圖將被刪除。具有透明背景的Objective-C模態視圖控制器

self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5]; 
[self setModalPresentationStyle:UIModalPresentationFullScreen]; 
[self setDefinesPresentationContext:YES]; 

然後呈現視圖控制器代碼

SecondViewController *alertView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
[self presentViewController:alertView animated:YES completion:nil]; 

請看鏈接 image/linke.gif

+2

可能的[iOS - 半透明模態視圖控制器]的副本(http://stackoverflow.com/questions/18902059/ios-semi-transparent-modal-view-controller) –

+0

究竟是@JamesP .. – vaibhav

回答

0

嘗試在按鈕的動作該代碼在firstViewController更改視圖控制器並呈現新類別secondViewController

secondViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"]; 

    VC.view.backgroundColor=[UIColor colorWithWhite:0 alpha:0.1f]; 
    VC.modalPresentationStyle=UIModalPresentationOverCurrentContext; 
    [self presentViewController:VC animated:NO completion:nil];