在主视图Swift中嵌入子视图 [英] Embedding subview in main view Swift

查看:118
本文介绍了在主视图Swift中嵌入子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你看一下这张图片(我不想上传它,因为它不属于我),你会在iPad的设置应用程序中看到主uiview控制器内部的uiview。我的问题是,我如何以编程方式复制这个?换句话说,我如何在另一个中嵌入UIView?

If you look at this image (I don't want to upload it, as it does not belong to me), you will see what appears to be a uiview inside the main uiview controller in the settings app of an iPad. My question is, how do I replicate this programatically? In other words, how do I embed a UIView in another?

以下是我所知道和已经完成的事情:

Here's what I know and have done:


  • 根据我的研究,这称为子视图。这是正确的吗?

  • 我在界面构建器中创建了一个带有我想要的正确元素的UIView。它目前不是一个子视图,但在层次上与我的主视图相同。

  • 我发现同样的问题,除了Obj-C,而不是我的语言(Swift)。

  • Based on my research, this is called "subviews". Is this correct?
  • I have created a UIView with the proper elements that I want in interface builder. It is currently not a subview, but at the same level hierarchically as my main view.
  • I found the same exact question except in Obj-C, not my language (Swift).

这就是我需要的:


  • 单击按钮后,如何以编程方式在swift中生成子视图?

  • 由于此子视图在UIelements方面非常复杂,我希望能够在界面构建器中进行设计。 / li>
  • How do I programatically spawn a subview in swift once a button is clicked?
  • As this subview is pretty complex in terms of UIelements, I want to be able to design it in interface builder.

这是我到目前为止所拥有的:

Here's what I have so far:

 @IBAction func buttonPressedSpawnSubview(sender: AnyObject) {
    //Open a subview from Interface builder.
}
@IBAction func closeButtonPressedSpawnSubview(sender: AnyObject) {
        //kill the subview.

有人可以帮我弄清楚如何填写注释行吗?

Can someone help me figure out how fill in the commented lines?

推荐答案

你所看到的是另一个视图之上的模态UIView。

What you are seeing is a modal UIView on top of another view.

来自内部的一个例子您可见的ViewController将是:

An example from within your visible ViewController would be:

    self.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal // Choose whatever transition you want
    self.modalPresentationStyle = .CurrentContext // Display on top of current UIView
    self.presentViewController(yourNewViewObject, animated: true, completion: nil)

这篇关于在主视图Swift中嵌入子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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