ios - UIViewController Storyboard 自定义尺寸

标签 ios uiviewcontroller storyboard uikit uistoryboard

我计划显示一个小型设置菜单,其中包含很少的 UISegmentControls 和 slider 。我不想全屏显示它,只是将其显示为 View Controller 中的 subview 。一种方法是将其完全定义为 UIView 的子类,但所有设计都必须在 xib 文件而不是 Storyboard 中完成。我的问题:

  1. 这里正确的方法是什么 - UIViewController、UIView 或两者中的任何一个?

  2. 如果我们走UIViewController路线,我们如何设计 Storyboard中具有自定义尺寸的 View ?

最佳答案

这两种方法都很好。

但我个人更喜欢UIViewController

在 Storyboard 中设计 ViewController 时,我将主视图的背景颜色设置为清晰(或者有时是黑色,alpha 在 0 到 0.5 之间);现在,我在主视图中添加其他 subview ,大小不限。

现在在呈现给定的 View Controller 时,请确保您正在为 modalPresentationStyle 使用 .overCurrentContext

使用代码作为

myVC?.modalPresentationStyle = .overCurrentContext;
self.present(myVC!, animated: false, completion: nil);

如果您使用不同的 modalPresentationStyle 那么,您的背景将看起来是纯黑色。但是,如果您使用 overCurrentContext,那么新的 View Controller 将显示在当前 View Controller 之上,因此,如果您保持背景颜色清晰,那么它将是透明的。

关于ios - UIViewController Storyboard 自定义尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52737356/

相关文章:

ios - UICollectionView:ObjC Apple 示例代码到 Swift 的转换(找不到成员)

ios - 我们是否需要为所有 iPhone/iPad 设备提供单独的 Storyboard?

ios - iPad中大量大图像的内存泄漏

ios - 在 Xcode 5 中使用 Mogenerator

ios - 后台运行的iPhone应用程序可以通过USB接口(interface)传输数据吗?

arrays - UISearchbar 并在 View a controller xcode swift 中传递数据

ios - iphone x 中的 UICollection header 已满

ios - UIViewController View 的框架在呈现后发生变化(viewController : animated: completion: )

ios - 删除 MainStoryboard 后黑屏

ios - 小于或等于约束总是相等的