模糊不匹配图像视图Swift的大小

时间:2016-05-20 18:04:09

标签: swift image view uiblureffect

enter image description here

我试图创建一个模糊的登录屏幕,我查找了如何在线进行操作。当我将约束应用于图像视图时(根据我的理解/思考),它不适用于模糊的部分。

import UIKit

class ViewController: UIViewController {

    @IBOutlet var mainBackgroundImage: UIImageView!
    override func viewDidLoad() {
        self.view.layoutIfNeeded()
        self.blurMainImg()
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func blurMainImg(){
        let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
        let blurView = UIVisualEffectView(effect: blurEffect)
        blurView.frame = mainBackgroundImage.bounds
        mainBackgroundImage.addSubview(blurView)
    }

}

enter image description here

1 个答案:

答案 0 :(得分:0)

当你在你的图片中发帖时,似乎是一个约束(前导和尾随)的问题,你必须删除它并将尾随约束放到Superview = 0,同样对于前导 - > Superview = 0

一个例子(寻找尾随和领先):

enter image description here

P.S。:不要忘记通过更新约束来发出无声警告(点击黄色三角形并标记所有)

enter image description here