gpt4 book ai didi

ios - removeFromSuperview() 几个 subview

转载 作者:行者123 更新时间:2023-11-28 07:37:32 26 4
gpt4 key购买 nike

我在 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)
}

然后我调用并关闭了我的弹出窗口(它完美地工作): enter image description here

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)
}

因为他不再申请这个图层和 View 。我将 2 个 subview 强加于另一个可能是不正确的。但是我不知道如何在我的表格下实现模糊效果 enter image description here

我该如何修复它?关闭所有内容,包括我的表单和 blurView, map 除外。

最佳答案

你需要给每个 subview 一个标签

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)
}

关于ios - removeFromSuperview() 几个 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53012126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com