Lalo
Lalo

Reputation: 438

UIVisualEffectView Mask not working on iPhone 7 Plus Simulator

I'm trying to round the two top corner of a UIVisualEffectView like this:

    if let tabBarHeight = self.tabBarController?.tabBar.frame.height {
        mainViewHeight = self.view.frame.height - tabBarHeight
    }

    let oneAndHalfMainViewHeight = mainViewHeight * 1.5
    midStateHeight = mainViewHeight/2 - midStateConstant
    let blur = UIBlurEffect(style: .dark)
    slideView = UIVisualEffectView(effect: blur)
    slideView.translatesAutoresizingMaskIntoConstraints = false
    slideView.contentView.backgroundColor = Tools.colorPicker(2, alpha: 1)
    self.view.addSubview(slideView)

    let slideViewHorizontalConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|[slideView(\(UIScreen.main.bounds.width))]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["slideView" : slideView])
    slideViewHeightConstraint = NSLayoutConstraint(item: slideView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: oneAndHalfMainViewHeight)
    slideViewTopConstraint = NSLayoutConstraint(item: self.view, attribute: .bottom, relatedBy: .equal, toItem: slideView, attribute: .top, multiplier: 1, constant: alwaysVisibleHeight)
    self.view.addConstraints(slideViewHorizontalConstraints)
    guard let slideViewHeightConstraint = slideViewHeightConstraint, let slideViewTopConstraint = slideViewTopConstraint else {
        return
    }
    self.view.addConstraint(slideViewHeightConstraint)
    self.view.addConstraint(slideViewTopConstraint)

    mainViewHeight = self.view.frame.height
    midStateHeight = mainViewHeight/2 - midStateConstant
    slideViewHeightConstraint.constant = oneAndHalfMainViewHeight

    let maskLayer = CAShapeLayer()
    let roundedRect = CGRect(x: 0, y: 0, width: view.bounds.width, height: oneAndHalfMainViewHeight)
    maskLayer.frame = roundedRect
    maskLayer.path = UIBezierPath(roundedRect: roundedRect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath

    let frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: oneAndHalfMainViewHeight)
    let maskView = UIView(frame: frame)

    maskView.layer.addSublayer(maskLayer)
    slideView.mask = maskView

When I try it on my iPhone 7 it works as expected but on the simulator of an iPhone 7 Plus the visual effect isn't shown and I don't have a real iPhone 7 Plus to try it. The simulator shows the effect for the iPhone 5s, SE, 6 and 7. So I was wondering if there could be a problem with my code given the huge size or is it a problem with the rendering on the Simulator. I'm using a 2016 15" Macbook Pro, the 7 Plus barely fits on the screen at 100%. Thank you!

Note: This is happening on the latest relase of Xcode and on Xcode beta 4.

Update: I've been able to try on a real iPhone 6s Plus and is working as expected so definitely a Simulator graphics problem.

Upvotes: 0

Views: 341

Answers (1)

Lalo
Lalo

Reputation: 438

I've been able to try on a real iPhone 6s Plus and is working as expected so definitely a Simulator graphics problem.

Upvotes: 0

Related Questions