deh*_*len 15 ios swift uivisualeffectview
我试图模糊MKMapView,同时在它上面显示一个圆形面具.为了更好地形象化我的意思,您可以找到我当前所附状态的图像:
这显示了我想要的几乎,但背景(地图)应该模糊,这不是这张图片中的情况.我尝试使用UIVisualEffectView,但似乎我在那里做错了.这是我尝试过的:
func createOverlay(at: CGPoint) {
var blur: UIView!
blur = UIVisualEffectView (effect: UIBlurEffect (style: UIBlurEffectStyle.dark))
blur.frame = self.mapView.frame
blur.isUserInteractionEnabled = false
self.mapView.addSubview(blur)
let circleSize: CGFloat = 200
let path = UIBezierPath (
roundedRect: blur.frame,
cornerRadius: 0)
let circle = UIBezierPath (
roundedRect: CGRect (origin: CGPoint(x:at.x - circleSize/2, y: at.y-circleSize/2),
size: CGSize (width: circleSize, height: circleSize)), cornerRadius: circleSize/2)
path.append(circle)
path.usesEvenOddFillRule = true
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
maskLayer.fillRule = kCAFillRuleEvenOdd
let borderLayer = CAShapeLayer()
borderLayer.path = circle.cgPath
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.lineWidth = 10
blur.layer.addSublayer(borderLayer)
blur.layer.mask = maskLayer
}
Run Code Online (Sandbox Code Playgroud)
总结这里是我的问题: 我如何更改我的代码以模糊mapview以及显示它上面的cirlce面具?
编辑 刚刚发现如果我删除代码以添加圆形蒙版,mapview的模糊效果......也许这对于解决这个问题是有意义的.
Jac*_*ley 19
我现在找到一个解决方案后挖了一下.我假设你使用Xcode 8作为layer.mask有一个已知的错误,你不能同时拥有模糊和掩码.
在操场上玩弄后我已经修复了问题,因此会尝试调整您的代码以匹配我的解决方案.如果您使用blurView的"mask"属性,那么您应该没有问题.有一个错误报告发给Apple我相信关于layer.mask不起作用
这是您最后的当前代码
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
maskLayer.fillRule = kCAFillRuleEvenOdd
let borderLayer = CAShapeLayer()
borderLayer.path = circle.cgPath
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.lineWidth = 10
blur.layer.addSublayer(borderLayer)
blur.layer.mask = maskLayer
Run Code Online (Sandbox Code Playgroud)
而不是这样,尝试使用以下内容:
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
maskLayer.fillRule = kCAFillRuleEvenOdd
let borderLayer = CAShapeLayer()
borderLayer.path = circle.cgPath
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.fillColor = UIColor.clear.cgColor //Remember this line, it caused me some issues
borderLayer.lineWidth = 10
let maskView = UIView(frame: self.view.frame)
maskView.backgroundColor = UIColor.black
maskView.layer.mask = maskLayer
blur.layer.addSublayer(borderLayer)
blur.mask = maskView
Run Code Online (Sandbox Code Playgroud)
如果您有任何问题,请告诉我!
| 归档时间: |
|
| 查看次数: |
4689 次 |
| 最近记录: |