【发布时间】:2018-07-25 18:52:34
【问题描述】:
我试图在点击后隐藏视图。为了做到这一点,我使用 touchesBegan 来检测视图是否被点击,如果是,它应该执行一个操作,例如隐藏视图和顶部的视图。定义了这两个视图:
@IBOutlet weak var theDarkView: UIView!
@IBOutlet weak var theFinalView: UIView!
这是我想出的代码。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//-- hides the view whenever its touched
if let touch = touches.first {
if touch.view == self.theDarkView {
if theDarkView.isHidden == false || theFinalView.isHidden == false {
theDarkView.isHidden = true
theFinalView.isHidden = true
}
} else {
return
}
}
}
如果你能帮助我并告诉我正确的方法来解决这个问题,并告诉我我在哪里搞砸了我的方法,那将不胜感激!
【问题讨论】:
-
似乎有什么问题?
-
DarkView和FinalView存在于哪个视图中?
-
您的代码有效。如果你触摸 theDarkView 设置隐藏到两个视图。
-
你也想隐藏自己?
-
当我按下视图时视图并没有隐藏,它们已连接到情节提要
标签: ios swift xcode view uiviewcontroller