简体   繁体   English

在主视图中嵌入子视图Swift

[英]Embedding subview in main view Swift

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. 如果您查看此图像 (我不想上传它,因为它不属于我),您将在iPad的设置应用程序的主uiview控制器中看到似乎是uiview的内容。 My question is, how do I replicate this programatically? 我的问题是,如何以编程方式复制此内容? In other words, how do I embed a UIView in another? 换句话说,如何将UIView嵌入另一个视图中?

Here's what I know and have done: 这是我所知道并已完成的工作:

  • 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. 我创建了一个UIView,并在接口构建器中使用了适当的元素。 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). 除了在Obj-C中,我发现了相同的问题 ,而不是我的语言(Swift)。

Here's what I need: 这是我需要的:

  • 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. 由于此子视图在UIelements方面非常复杂,因此我希望能够在界面生成器中进行设计。

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? 有人可以帮我弄清楚如何填写注释行吗?

What you are seeing is a modal UIView on top of another view. 您将看到的是另一个视图之上的模式UIView。

An example from within your visible ViewController would be: 您可见的ViewController中的示例为:

    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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM