[英]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: 我的问题:
What is the right approach here - UIViewController, UIView, or any of the two? 什么是正确的方法-UIViewController,UIView或两者之一?
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.