简体   繁体   English

UIVisualEffectView蒙版在iPhone 7 Plus Simulator上不起作用

[英]UIVisualEffectView Mask not working on iPhone 7 Plus Simulator

I'm trying to round the two top corner of a UIVisualEffectView like this: 我试图像这样将UIVisualEffectView的两个上角四舍五入:

    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. 当我在iPhone 7上尝试使用它时,可以按预期工作,但是在iPhone 7 Plus的模拟器上没有显示视觉效果,而且我没有真正的iPhone 7 Plus可以尝试。 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. 该模拟器显示了iPhone 5s,SE,6和7的效果。因此,我想知道由于巨大的尺寸,我的代码是否可能存在问题,还是模拟器上的渲染存在问题? I'm using a 2016 15" Macbook Pro, the 7 Plus barely fits on the screen at 100%. Thank you! 我使用的是2016年15英寸Macbook Pro,那么7 Plus几乎无法100%适应屏幕。谢谢!

Note: This is happening on the latest relase of Xcode and on Xcode beta 4. 注意:这是在最新版本的Xcode和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. 更新:我已经可以尝试使用真正的iPhone 6s Plus,并且可以按预期工作,因此肯定是模拟器图形问题。

我已经能够尝试使用真正的iPhone 6s Plus,并且按预期工作,因此绝对是模拟器图形问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM