使用ViewContainer中的按钮隐藏视图容器 [英] Hide a view container with a button in the ViewContainer
问题描述
我有查看
。在这个视图中,我有一个容器视图
。在 ContainerView
我有一个按钮。
I have a View
. In this view, I have a Container View
. And in the ContainerView
I have a button.
当我触摸ContainerView的按钮时,我想要ContainerView变得隐藏。
When I am touching the button of the ContainerView, I want the ContainerView become hidden.
我想做类似的事情:
class ContainerView: UIViewController {
@IBAction func closeContainerViewButton(sender: AnyObject) {
//I try this : self.hidden = false
//or this : self.setVisibility(self.INVISIBLE)
}
}
任意想法怎么做?
推荐答案
有些方法,但这里最简单,但不是最漂亮。你应该真的使用委托,但这是一个开始的hacky方式。只需创建一个包含容器的类的全局变量(在本例中为startController)。然后从你的其他视图控制器(MyViewInsideContainer)调用它并告诉它隐藏你所在的视图。我没有运行这个代码但它应该工作。
There are serval ways but here is the easiest one, not prettiest though. You should really use delegates but this is a hacky way to get started. Just create a global variable of the class that holds the container (startController in this case). Then call it from your other view controller (MyViewInsideContainer) and tell it to hide the view you´re in. I have not run this code but it should work.
var startController = StartController()
class StartController:UIViewController {
@IBOutlet var myViewInsideContainerView: UIView
....
override func viewDidLoad() {
super.viewDidLoad()
startController = self
}
func hideContainerView(){
self.myContainerView.hidden = true
}
}
class MyViewInsideContainer:UIViewController {
...
@IBAction func hideThisView(sender: AnyObject) {
startController.hideContainerView()
}
}
这篇关于使用ViewContainer中的按钮隐藏视图容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!