我有一个视图
.在这个视图中,我有一个 Container View
.在 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)
}
}
知道怎么做吗?
有多种方法,但这里是最简单的一种,虽然不是最漂亮的.你真的应该使用委托,但这是一种入门的方式.只需创建一个包含容器的类的全局变量(在本例中为 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 youre 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 中的按钮隐藏视图容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!