SWIFT - 隐藏与在ViewContainer一个按钮View容器 [英] SWIFT - Hide a view container with a button in the ViewContainer

查看:1987
本文介绍了SWIFT - 隐藏与在ViewContainer一个按钮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)
}

}

这是知道怎么做呢?
谢谢你。

An idea how do it ? Thank you.

推荐答案

有薮方式,但这里是一个最简单的,而不是prettiest虽然。只是创建一个保存容器(startController在这种情况下)的类的全局变量。然后将其他视图控制器(MyViewInsideCoinainer)调用它,告诉它隐藏视图you're。我还没有运行该code,但它应该工作。

There are serval ways but here is the easiest one, not prettiest though. Just create a global variable of the class that holds the container (startController in this case). Then call it from your other view controller (MyViewInsideCoinainer) 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 MyViewInsideCoinainer:UIViewController {

    ...

    @IBAction func hideThisView(sender: AnyObject) {
        startController.hideContainerView()
    }

}

这篇关于SWIFT - 隐藏与在ViewContainer一个按钮View容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆