2017-06-18 60 views
0

我想創建一個模糊和約束的UIImageView。但模糊不想與約束一起工作。UIImageView,約束和模糊編程

我的代碼:

var notifBackground: UIImageView! 
    notifBackground = UIImageView() 
    notifBackground.backgroundColor = UIColor.clear 
    view.addSubview(notifBackground) 

    notifBackground.translatesAutoresizingMaskIntoConstraints = false 
    notifBackground.widthAnchor.constraint(equalToConstant: 200).isActive = true 
    notifBackground.heightAnchor.constraint(equalToConstant: 200).isActive = true 
    notifBackground.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true 
    notifBackground.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true 

    let blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.regular)) 
    blur.frame = notifBackground.bounds 
    view.addSubview(blur) 

回答

0

在你模糊的邊界設置爲ImageView的同一範圍時,佈局限制尚未處理。 你必須做的是設置相似的模糊限制。通過這樣做,模糊會有類似的邊界,並出現在imageview的頂部。

0

模糊效果

let blur = UIBlurEffect(style: UIBlurEffectStyle.regular) 
      let blurView = UIVisualEffectView(effect: blur) 
      blurView.frame = view.bounds 
      blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 
      view.addSubview(blurView)