用 ViewContainer 中的按钮隐藏视图容器

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)