模糊的UIImageView大小调整问题

时间:2017-06-07 19:20:12

标签: ios swift uiimageview blur

我呈现的UIViewController有一个UIImageView,即backgroundImageView,作为VC的背景并设置为填满整个屏幕。

我希望UIImageView能够呈现iOS提供的暗模糊效果,但是当我第一次呈现视图控制器时,会暂时出现以下大小调整问题(在设备上但不在模拟器上):

Problematic Blur Size

内部viewDidLoad()

// `locationImage` is passed during the segue
backgroundImageView.image = locationImage
backgroundImageView.contentMode = .scaleAspectFill

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

上述视图控制器的modalPresentationStyle设置为currentContext

如果我暂时删除模糊效果,我会看到我给视图控制器设置的背景图像已正确设置。但是,一旦应用了模糊效果,就会立即出现尺寸问题。

究竟是什么导致了这个?

1 个答案:

答案 0 :(得分:0)

尝试在viewWillLayoutSubviews()viewDidLayoutSuviews()

中设置blurEffectView的框架

here您可以找到有关viewcontroller生命周期的更多信息

相关问题