標籤:
最近項目有需求, 需要模態初一個半透明的視圖, 好多人都碰到這個問題吧, 在目標視圖中設定背景顏色然後發現模態動作結束後變成了黑色或者不是半透明的顏色。
所以今天來告訴大家解決方案
- (IBAction)Avtion1:(id)sender { TestViewController * testVC = [TestViewController new]; self.definesPresentationContext = YES; //self is presenting view controller testVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4]; testVC.modalPresentationStyle = UIModalPresentationOverCurrentContext; [self presentViewController:testVC animated:YES completion:nil];}
- definesPresentationContext
/* Determines which parent view controller‘s view should be presented over for presentations of type UIModalPresentationCurrentContext. If no ancestor view controller has this flag set, then the presenter will be the root view controller.*/
設定你的背景顏色
/* Defines the transition style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter. Defaults to UIModalTransitionStyleCoverVertical.*/
iOS 類比出一個半透明的ViewController presentViewController 實現