[英]Blur view controller while presenting Uialertview
我想按一下按鈕,它將彈出UIAlertView
。 我想知道是否可以對UIAlertView
周圍的所有內容進行模糊處理,例如在該視圖控制器上添加模糊處理效果。 我花了2個小時來尋找解決方案,但沒有達到我的預期。 我想在圖片上做同樣的事情
您需要使用UIBlurEffect
和UIVisualEffectView
這里的代碼應如下所示:
- (IBAction)buttonClicked:(id)sender
{
// Create blur effect
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
// Add effect to an effect view
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = self.view.frame;
self.alertController = [UIAlertController alertControllerWithTitle: @"Alert"
message: nil
preferredStyle: UIAlertControllerStyleAlert];
[self.alertController addAction:[UIAlertAction actionWithTitle: @"Cancel" style: UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[visualEffectView removeFromSuperview];
}]];
[self.view addSubview:visualEffectView];
[self presentViewController: self.alertController animated: true completion: nil];
}
結果:
迅捷3
@IBAction func buttonClicked(_ sender: Any) {
// Create blur effect
let blurEffect = UIBlurEffect(style: .light)
// Add effect to an effect view
let visualEffectView = UIVisualEffectView(effect: blurEffect)
visualEffectView.frame = view.frame
alertController = UIAlertController(title: "Alert", message: nil, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: {(_ action: UIAlertAction) -> Void in
visualEffectView.removeFromSuperview()
}))
view.addSubview(visualEffectView)
present(alertController, animated: true, completion: { _ in })
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.