Hide a view container with a button in the ViewContainer(用 ViewContainer 中的按钮隐藏视图容器)
问题描述
我有一个视图
.在这个视图中,我有一个 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 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 中的按钮隐藏视图容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用 ViewContainer 中的按钮隐藏视图容器


- GPS状态的广播接收器? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- URL编码Swift iOS 2022-01-01
- UITextView 内容插图 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01