I'm not sure what could be wrong. I pasted the following in a new project and it works for me:
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
let mapView: MKMapView = {
let map = MKMapView()
map.translatesAutoresizingMaskIntoConstraints = false
return map
}()
let blurredView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(mapView)
view.addSubview(blurredView)
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = blurredView.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurredView.addSubview(blurEffectView)
setupConstraints()
view.layoutIfNeeded()
print("height: \(blurredView.bounds.height)")
additionalSafeAreaInsets = UIEdgeInsetsMake(0.0, 0.0, blurredView.bounds.height, 0.0)
print("additionalSafeAreaInsets: \(additionalSafeAreaInsets)")
}
var mapViewTopAnchor: NSLayoutConstraint!
var mapViewLeftAnchor: NSLayoutConstraint!
var mapViewRightAnchor: NSLayoutConstraint!
var mapViewBottomAnchor: NSLayoutConstraint!
var blurredViewHeightAnchor: NSLayoutConstraint!
var blurredViewLeftAnchor: NSLayoutConstraint!
var blurredViewRightAnchor: NSLayoutConstraint!
var blurredViewBottomAnchor: NSLayoutConstraint!
func setupConstraints() {
mapViewTopAnchor = mapView.topAnchor.constraint(equalTo: view.topAnchor)
mapViewLeftAnchor = mapView.leftAnchor.constraint(equalTo: view.leftAnchor)
mapViewRightAnchor = mapView.rightAnchor.constraint(equalTo: view.rightAnchor)
mapViewBottomAnchor = mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
NSLayoutConstraint.activate([mapViewTopAnchor, mapViewLeftAnchor, mapViewRightAnchor, mapViewBottomAnchor])
blurredViewHeightAnchor = blurredView.heightAnchor.constraint(equalToConstant: 100)
blurredViewLeftAnchor = blurredView.leftAnchor.constraint(equalTo: view.leftAnchor)
blurredViewRightAnchor = blurredView.rightAnchor.constraint(equalTo: view.rightAnchor)
blurredViewBottomAnchor = blurredView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
NSLayoutConstraint.activate([blurredViewHeightAnchor, blurredViewLeftAnchor, blurredViewRightAnchor, blurredViewBottomAnchor])
}
}
Screenshot: https: //postimg.org/image/1ibzeggam3/
The output from the print statements:
height: 100.0
additionalSafeAreaInsets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 100.0, right: 0.0)
Check what output you get.