ios - removeFromSuperview() 几个子视图
问题描述
我在ViewHelper
Class 有一些功能:
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 个子视图强加给另一个可能是不正确的。但是我不知道如何实现我的表单下的模糊效果
我该如何解决?关闭所有东西,我的表单和模糊视图,地图除外。
解决方案
你需要给每个子视图一个标签
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)
}
推荐阅读
- scala - 如何在 Slick 中设置 ThreadPool 大小?
- java - Solr DIH 端点上的“ArrayList 无法转换为 java.lang.String”错误消息
- php - 如何在相等的部分中循环数组和块?
- c# - 在 C# 中格式化十进制数
- python - 格式化 AWS lambda 请求的 Python 错误
- hyperledger-fabric - 无法使用 Hyperledger Fabric 节点 SDK 让对等方加入频道
- python - Keras 加载模型
- c# - 在 Python 中模仿 C# 类
- scripting - 用于修改身份验证数据条目的 wsadmin 脚本/命令参数
- python - TypeError:“int”对象不可下标 - 尝试创建 csv 文件时