2017-08-29 73 views
0

我在storyBorad中使用UIVisual Effect視圖。我只是將四個約束(頂部,底部,左側,右側)設置爲該視圖。但它看起來有些黑色背後。無法獲得模糊效果

源代碼:

import UIKit 

class SignOutViewController: UIViewController { 

    @IBOutlet weak var signouTitle: UILabel! 
    @IBOutlet weak var desc1: UILabel! 
    @IBOutlet weak var desc2: UILabel! 
    @IBOutlet weak var cancelButton: UIButton! 
    @IBOutlet weak var sureButton: UIButton! 
    @IBOutlet weak var alertView: UIView! 
    @IBOutlet weak var seperatorView: UIView! 
    @IBOutlet weak var buttonsSuperView: UIView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     prepareAlertView() 
    } 

    override func viewWillAppear(_ animated: Bool) { 
     super.viewWillAppear(animated) 
     alertView.layer.cornerRadius = alertView.frame.height * 0.05 

    } 

    private func prepareAlertView() -> Void{ 
     signouTitle.text = "Sign Out" 
     desc1.text = "Do you really want to sign out" 
     desc2.text = "from this account" 
     signouTitle.textColor = UIColor(red: 1/255, green: 170/255, blue: 112/255, alpha: 1) 
     desc1.textColor = UIColor(red: 195/255, green: 195/255, blue: 195/255, alpha: 1) 
     desc2.textColor = UIColor(red: 195/255, green: 195/255, blue: 195/255, alpha: 1) 
     cancelButton.setAttributedTitle(NSAttributedString(string: "Cancel", attributes: [NSFontAttributeName: UIFont.getProximaNovaSemibold(size: 16), NSForegroundColorAttributeName: UIColor.white]), for: .normal) 
     sureButton.setAttributedTitle(NSAttributedString(string: "Sure", attributes: [NSFontAttributeName: UIFont.getProximaNovaSemibold(size: 16), NSForegroundColorAttributeName: UIColor.white]), for: .normal) 
     self.view.backgroundColor = UIColor.black.withAlphaComponent(0.65) 
     buttonsSuperView.backgroundColor = UIColor(red: 1/255, green: 170/255, blue: 112/255, alpha: 1) 
     alertView.backgroundColor = UIColor(red: 36/255, green: 36/255, blue: 40/255, alpha: 1) 
    } 

    @IBAction func cancelTapped(_ sender: Any) { 
     self.dismiss(animated: true, completion: nil) 
    } 

    @IBAction func sureTapped(_ sender: Any) { 
    } 

} 

我加入UIVisual effectView編程方式。我需要visualEffect作爲viewHierarchy中的第-1個位置。但它作爲響應相同..

+0

提供你已經寫好 – Praveen

+0

@Praveen源代碼被添加到後.. –

回答

0

試試這個

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark) 
let blurEffectView = UIVisualEffectView(effect: blurEffect) 
blurEffectView.frame = view.bounds 
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 
view.addSubview(blurEffectView) 
+0

感謝您的建議代碼。但它不是沃金too.I更新後需要考慮這樣做...... –

+0

我看到你的截圖ü可以用的UIImage做這個,你必須做出與左上環切和Alpha一個圖像〜0.8,並採取UIView的再取爲的UIImageView的UIView的子類,並把你的圖像中的UIImageView然後讓你的彈出確定或取消,最後你可以隱藏和顯示你的UIView。 –

0

我面對完全一樣的問題。我所做的只是使用了一個新的故事板,並使用屏幕截圖中的設置以模態方式呈現它。模糊效果然後完美的作品,而不是顯示黑屏。如果你想以編程方式進行編譯,你也可以將它翻譯成代碼。

注意:這些設置適用於segue。

enter image description here