我在ViewHelper
类中有一些功能:
class func showFrontPopOver(popOver:UIView,view:UIView) {
let animation = AnimationType.zoom(scale: 1.5)
popOver.animate(animations: [animation])
popOver.layer.cornerRadius = 10
popOver.center = view.center
view.addSubview(popOver)
}
class func hidePopOver(popOver:UIView, view:UIView) {
UIView.transition(with: view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
popOver.removeFromSuperview()
}, completion: nil)
}
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
ViewHelper.showFrontPopOver(popOver: popOver, view: self.view)
return true
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
ViewHelper.hidePopOver(popOver: self.popOver, view:self.view)
}
但是我不想在我的showFrontPopOver
方法中添加blurView:
class func showFrontPopOver(popOver:UIView,view:UIView) {
let animation = AnimationType.zoom(scale: 1.5)
popOver.animate(animations: [animation])
popOver.layer.cornerRadius = 10
popOver.center = view.center
let blurEffect = UIBlurEffect(style: .light)
let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurVisualEffectView.frame = view.bounds
blurVisualEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurVisualEffectView)
view.addSubview(popOver)
}
事实证明该方法无效:
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
ViewHelper.hidePopOver(popOver: self.popOver, view:self.view)
}
因为他不再应用于该图层和视图。 我强加2个子视图可能是不正确的。 但是我不知道如何在我的形式下实现模糊效果
我该如何解决?关闭除地图之外的所有内容,包括窗体和blurView。
答案 0 :(得分:0)
您需要为每个子视图添加一个标签
op1
class func showFrontPopOver(popOver:UIView,view:UIView) {
let animation = AnimationType.zoom(scale: 1.5)
popOver.animate(animations: [animation])
popOver.layer.cornerRadius = 10
popOver.center = view.center
let blurEffect = UIBlurEffect(style: .light)
let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurVisualEffectView.frame = view.bounds
blurVisualEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
popOver.tag = 11
blurVisualEffectView.tag = 11
view.addSubview(blurVisualEffectView)
view.addSubview(popOver)
}
然后
class func hidePopOver(popOver:UIView, view:UIView) {
UIView.transition(with: view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
view.subviews.forEach {
if $0.tag == 11 {
$0.removeFromSuperview()
}
}, completion: nil)
}
op2
class func hidePopOver(view:UIView) {
UIView.transition(with: view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
view.subviews.last?.removeFromSuperview()
view.subviews.last?.removeFromSuperview()
}, completion: nil)
}