我计划显示一个小型设置菜单,其中包含很少的 UISegmentControls 和 slider 。我不想全屏显示它,只是将其显示为 View Controller 中的 subview 。一种方法是将其完全定义为 UIView 的子类,但所有设计都必须在 xib 文件而不是 Storyboard 中完成。我的问题:
这里正确的方法是什么 - UIViewController、UIView 或两者中的任何一个?
如果我们走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/