我试图像这样绕过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
当我在iPhone 7上试用它时,它按预期工作,但在iPhone 7 Plus的模拟器上没有显示视觉效果,我没有真正的iPhone 7 Plus试用它。模拟器显示了iPhone 5s,SE,6和7的效果。所以我想知道我的代码是否存在问题,考虑到巨大的尺寸或者是模拟器上的渲染问题。我使用2016年15" Macbook Pro,7 Plus几乎不适合100%的屏幕。谢谢!
注意:这是在Xcode和Xcode beta 4的最新版本上发生的。
更新:我已经能够试用真正的iPhone 6s Plus,并且正如预期的那样工作,这绝对是模拟器图形问题。
答案 0 :(得分:0)
我已经能够尝试使用真正的iPhone 6s Plus并且按预期工作,这绝对是模拟器图形问题。