I would like to implement UIVisualEffectView
to apply a blur effect to a view to show the view that lies behind it.
This view that should have its background blurred is a UITableViewController
that is embedded in a UINavigationController
, and it will either be presented in a popover on iPad or it will be presented full screen modally on iPhone, thanks to iOS 8 adaptive segues (Present as Popover). When this view controller is in a popover I want the background to blur what's underneath the popover, and when it's presented full screen I want the background to blur the previous view controller.
I have tried to implement this and have not been successful. I cannot even get the blur effect to work for the popover. I thought this code should do the trick:
//In viewDidLoad on the UITableViewController subclass:
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
effectView.frame = tableView.frame
tableView.addSubview(effectView)
I also tried adding the subview to the tableView.backgroundView
, I tried setting the backgroundView
to my effectView
, I tried using Autolayout constraints instead of setting the frame, but nothing has worked. Can you help me accomplish the desired behavior?
An example of what I am trying to obtain:
iPad popover:
iPhone modal presentation:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…