简体   繁体   English

UIViewController故事板自定义大小

[英]UIViewController Storyboard custom size

I am planning to show a small settings menu which has few UISegmentControls and sliders. 我打算显示一个小的设置菜单,其中没有几个UISegmentControls和滑块。 I don't want to show it full screen, just show it as a subview in my view controller. 我不想全屏显示它,而只是在视图控制器中将其显示为子视图。 One way would be to define it as a subclass of UIView altogether but then all designing would have to be done in xib file rather than Storyboard. 一种方法是将其完全定义为UIView的子类,但是所有设计都必须在xib文件而不是Storyboard中完成。 My questions: 我的问题:

  1. What is the right approach here - UIViewController, UIView, or any of the two? 什么是正确的方法-UIViewController,UIView或两者之一?

  2. If we take UIViewController route, how do we design the view in storyboard with a custom size? 如果采用UIViewController路线,如何在故事板上以自定义大小设计视图?

Both the approaches are fine. 两种方法都很好。

But I personally prefer to have UIViewController . 但是我个人更喜欢UIViewController

While designing ViewController in Storyboard, I make main view's background color to clear(or sometimes black color with alpha between 0 to 0.5); 在Storyboard中设计ViewController时,我要清除主视图的背景色(或有时是黑色,alpha介于0到0.5之间); Now I add other subview inside main view with whatever size that i want. 现在,我可以在主视图中添加任意大小的其他子视图。

Now while presenting given view controller, make sure that you are using .overCurrentContext for modalPresentationStyle . 现在,在呈现给定的视图控制器时,请确保您使用.overCurrentContext作为modalPresentationStyle

Use code as 使用代码作为

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

If you use different modalPresentationStyle then, your background will look pure black. 如果您使用其他modalPresentationStyle则背景将显示为纯黑色。 But if you use overCurrentContext , then new view controller will be presented above current one, so, if you kept background color as clear then it will be transparent. 但是,如果您使用overCurrentContext ,那么新的视图控制器将显示在当前视图之上,因此,如果您将背景色保持为透明,那么它将是透明的。

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

相关问题 从 storyboard 自定义 UIViewController - Custom init of UIViewController from storyboard 呈现具有自定义尺寸的UIViewController - Presenting a UIViewController with a custom size 使用情节提要板在UIViewController中初始化自定义UIView - Initialization of a custom UIView in a UIViewController using a storyboard Swift 中 UIViewController 的自定义初始化,在 storyboard 中设置接口 - Custom init for UIViewController in Swift with interface setup in storyboard Storyboard uiviewcontroller,“自定义类”未显示在下拉列表中 - Storyboard uiviewcontroller, 'custom class' not showing in drop down Xcode 5无法识别故事板中的自定义UIViewController子类 - Xcode 5 does not recognize custom UIViewController subclass in storyboard 使用故事板重用自定义UIVIewController中的子项 - Reuse childs from custom UIVIewController using storyboard 以编程方式为自定义UIViewController设置情节提要ID? - Set storyboard ID programmatically for custom UIViewController? 如何将Storyboard UIViewController与我的自定义UIViewController类相关联? - How do I associate a Storyboard UIViewController with my custom UIViewController class? 具有XIB和自定义视图大小的UIViewController - UIViewController with XIB and custom view size
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM