UIModalPresentationFormSheet with transparent background?

Essentially here, I want the modal form to be transparent so that I can see the UIView behind it (this is full-screen mode).

Is it possible? Setting UIView for opacity and backgroundColor [UIColor clearColor] does not work.

I noticed that when I switch from UIModalPresentationFormSheet to a different presentation style, my review background is really transparent.

Where am I wrong?

+4
source share
2 answers

As far as I can tell, this is no longer possible. It used to be, but Apple turned off this feature.

Instead, I just created a UIView , as usual, and add them as subtitles to my main view. I have to reject my form sheet and then make this presentation.

+2
source

This worked for me:

 [modalView.superview setBackgroundcolor:[UIColor clearColor]]; 

It will still hide the appearance of the background transparently, but will not cover it with solid gray.

...............................................

UPDATE FOR iOS 8

My previous solution no longer works for iOS 8. There are many steps to get something like this to work in iOS 8. So I created a nice reusable solution: ModalController https://github.com/koreyhinton/ModalController .

It is very easy to use and automatically fires itself.

 let modal = ModalController() modal.content = myCustomView presentViewController(modal, animated: true, completion: nil) 

If you are interested in implementation details, here is how I did it:

Make your modal view controller full screen, and the main background of the view will switch between transparent and semi-dark. After that, you will have a view of the content, which will be modal, which will be centered by the solid background color. I also use the presentation style: .OverCurrentContext , which I assign in the init method.

 var content = UIView() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.clearColor() content.frame = CGRect(x:0, y:0, width:300, height:300) content.backgroundColor = UIColor.blackColor() view.addSubview(content) } override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.7) } override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) view.backgroundColor = UIColor.clearColor() } override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() content!.center = view.center } 
+3
source

Source: https://habr.com/ru/post/1390542/


All Articles