2017-02-20 128 views
0

我想在視圖控制器的視圖背景中使用模糊效果但有時它不起作用,當它工作時它將無法正常工作,當我在大型熨平板設備上運行程序時喜歡iPad有上頂部的黑色方塊,我無法看到的模糊效果模糊按鈕效果

這裏是我的代碼

class sahafiViewController: UIViewController , UIImagePickerControllerDelegate , UINavigationControllerDelegate { 




@IBOutlet weak var backgroundImg: UIImageView! 

override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view. 

    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark) 
    let blurView = UIVisualEffectView(effect: blurEffect) 
    blurView.frame = backgroundImg.bounds 
    backgroundImg.addSubview(blurView) 


} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
}} 

here is what happens

回答

0

嘗試在viewDidAppear方法你的代碼。

+0

不工作:(頁面將不會被模糊這將是完全黑 –

0

你可以試試這個代碼:

覆蓋FUNC viewDidLoad中(){

 super.viewDidLoad() 

    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light) 
    let blurView = UIVisualEffectView(effect: blurEffect) 

    blurView.frame = CGRect(x: self. backgroundImg.frame.origin.x, y: self. backgroundImg.frame.origin.y, width: self. backgroundImg.frame.size.width, height: self. backgroundImg.frame.size.height) 

    blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

    self.backgroundImg.addSubview(blurView) 
} 
+0

我不要!知道爲什麼!但它在小型iPhone中工作但在更大的屏幕設備(如iPhone plus和iPad)中,屏幕將在光線模糊中變爲灰色,在黑色模糊中變爲黑色! –

+0

我建議您檢查給出的背景圖像。框架應該正確給出然後,它會工作 – Priya

+0

我檢查,它是好的,我用這些代碼在另一個V iew控制器在另一個類,它沒有工作,所以問題是代碼 –