Hello,
i have the following view hierarchies:
1)
UIView (clearColor background)
|---UIView (clearColor background)
|--- BlurView (inherits UIVisualEffectsView)
2)
UIView (clearColor background)
|--- BlurView (inherits UIVisualEffectsView)
3)
UIViewController
|---MKMapView
|--- .... some other views
|---UIView == 1)
|---UIView == 2)
The code if the blurView is as follows:
class BlurView: UIVisualEffectView {
var cornersToRound = UIRectCorner.AllCorners
private override init(effect: UIVisualEffect?) {
super.init(effect: effect)
}
convenience init(effect: UIVisualEffect?, corners: UIRectCorner) {
self.init(effect: effect)
cornersToRound = corners
translatesAutoresizingMaskIntoConstraints = false
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
let radius = kDefaultCornerRadius
let path = UIBezierPath(roundedRect:bounds, byRoundingCorners:cornersToRound, cornerRadii: CGSizeMake(radius, radius))
let shapeLayer = CAShapeLayer()
let maskView = UIView(frame: bounds)
shapeLayer.path = path.CGPath
maskView.layer.mask = shapeLayer
maskView.backgroundColor = UIColor.blackColor()
self.maskView = maskView
}
}
In the first view hierarchy I don't get the blur plus the rounded corners but in the second one it works. The main differences are
a) Hierarchy 2) is added as reaction on a user button press when all views are already set up. Hierarchy 1) is added and shown in viewDidLoad of the viewController as shown in 3).
b) The blurView in hierarchy 1) must sample through 2 clear colored views. In hierarchy 2) it must sample through only 1 view.
c) In hierarchy 1) the rounded corners are only top left and top right. In hierarchy 2) all corners are rounded.
The effect appears only in iOS10 using either Xcodes 7 or 8. In iOS 9 it looks as expected (rounded corners + blurred background).