简体   繁体   中英

Transparent View Controller Background When Presented Full Screen

I present a view controller(B) over another(A) where I want the background of B to be transparent so that A is still visible in the background.

Therefore, before presenting B, it's modalPresentationStyle is set to be .overCurrentContext and B has view.backgroundColor = UIColor.clear so that the transparent background is present.

However when I dismiss B and return back to A, methods of A like viewDidAppear , viewWillAppear , etc. does not get re-triggered.

If I change the above modalPresentationStyle to .fullScreen , viewWillAppear and such will get re-triggered when returned back to A but this time, I lose the transparent background.

All in all, how can I achieve both a transparent background on the presented view and re-trigger methods such as viewDidAppear on A when I return back to A?

When you present full screen the presenting view is removed from view - so there is nothing to see through your transparent view. So this method will not work for you.

When you present over the current context the presenting view remains - but that is why viewDidAppear etc do not get called - it never went away so it has not re-appeared.

Instead of viewDidAppear use another method of detecting that your transparent view has been dismissed, such as an unwind segue or one of the other methods discussed in this SO answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM