gpt4 book ai didi

swift - 从任何地方删除任何 View ,例如从窗口

转载 作者:行者123 更新时间:2023-11-28 12:06:46 25 4
gpt4 key购买 nike

我在屏幕上有 2 个 View ,一个是底部的 overlayView,另一个是 overlayView 顶部的 introView。当我在屏幕上点击(tapToContinueAction)时,它们应该都隐藏或删除自己。

extension UIView {
....
func hideView(view: UIView, hidden: Bool) {
UIView.transition(with: view, duration: 0.5, options: .transitionCrossDissolve, animations: {
view.isHidden = hidden
})
}
}

class IntroScreen
@IBAction func tapToContinueAction(_ sender: UITapGestureRecognizer) {
self.hideView(view: self, hidden: true)
}

--

class OverlayView : UiView {
...
}

在当前情况下,我只能隐藏 introScreen,我不知道其他类的操作如何同时影响 overlayView 并隐藏该 View 。有什么想法吗?

最佳答案

您的 View 有两个不同的类。扩展您的窗口以删除您的特定 View ,就像我制作 removeOverlayremoveIntroView 一样,这两个计算属性将在 window< 的 subview 列表中搜索 并检查每个 View 的类型并删除它们。这就是您可以在任何地方删除任何 View 表单的方法。

class OverLayView: UIView {}
class IntroView: UIView {
@IBAction func didTapYourCustomButton(sender: UIButton) {
let window = (UIApplication.shared.delegate as! AppDelegate).window!
window.removeOverlay
window.removeIntroView
}
}
extension UIWindow {
var removeOverlay: Void {
for subview in self.subviews {
if subview is OverLayView {
subview.removeFromSuperview()// here you are removing the view.
subview.hidden = true// you can hide the view using this
}
}
}
var removeIntroView: Void {
for subview in self.subviews {
if subview is IntroView {
subview.removeFromSuperview()// here you are removing the view.
subview.hidden = true// you can hide the view using this
}
}
}
}

关于swift - 从任何地方删除任何 View ,例如从窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49272293/

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