【问题标题】:Blur Not matching the size of the image view Swift模糊不匹配图像视图 Swift 的大小
【发布时间】:2016-05-20 18:04:08
【问题描述】:

我正在尝试创建一个模糊的登录屏幕,并且我在网上查找了如何做到这一点。当我将约束应用于图像视图时,(据我了解/认为)它不适用于模糊部分。

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)
    }

}

【问题讨论】:

  • mainBackgroundImage 约束怎么样?您可以在您的问题中发布一些图片吗?
  • @AlessandroOrnano 我添加了故事板的图片和图像的约束
  • 优秀的工作人员,现在你的问题更清楚了..

标签: swift image view uiblureffect


【解决方案1】:

正如您在图片中发布的那样,这似乎是一个约束问题(前导和尾随),您必须将其删除并将尾随约束置于 Superview = 0,与前导相同 -> Superview = 0

一个例子(寻找尾随和前导):

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

【讨论】:

  • imgur.com/FtRevbd 我认为出了点问题。图像不是屏幕的全尺寸,模糊部分的尺寸仍然不一样。
  • 您必须通过单击并更新约束(全部)来静音警告(设置约束时的黄色三角形)
  • 当我将尾随和前导更改为 0 时,它只会缩小主图像,它不会随着模糊而改变任何东西。我目前有 0 个警告,但它仍然不起作用
猜你喜欢
  • 2018-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-30
  • 2015-04-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多