简体   繁体   English

使用Storyboard将UIView子视图作为UIViewController的默认UIView

[英]Make UIView subview as default UIView for UIViewController with Storyboard

I have a multi-viewcontroller app. 我有一个多视图控制器应用程序。

The main view of the main VC is subclassed so I can use Core Graphics animations. 主VC的主视图是子类的,因此我可以使用Core Graphics动画。 It's called "animations" class. 它称为“动画”类。

On the storyboard, I add a UIView called "MainArea" as a subview of the "animations". 在故事板上,我添加了一个名为“ MainArea”的UIView作为“动画”的子视图。 I have a VC called "MainAreaVC". 我有一个名为“ MainAreaVC”的VC。 As you know it has a property of "view". 如您所知,它具有“视图”的属性。 How can I make the "MainArea" subview the default UIView of my "MainAreaVC"? 如何使“ MainArea”子视图成为“ MainAreaVC”的默认UIView?

The other option is to just make the "MainArea" view a property of my "MainAreaVC" and use this. 另一种选择是仅使“ MainArea”视图成为我的“ MainAreaVC”的属性并使用它。 I just don't want the "MainAreaVC"'s default "view" property just hanging out doing nothing. 我只是不想让“ MainAreaVC”的默认“ view”属性闲逛而无所事事。

The view in a UIViewController is the bottom view: it is always the one at the root of the tree hierarchy, and appears behind everything else, possibly clipping subviews. viewUIViewController是底部的观点:它始终是一个在树层次结构的根,并出现其他一切的背后,可能是剪辑子视图。

You can change the view Class , but no matter what you do, by design it must be at the root. 您可以更改view Class ,但是无论您做什么,通过设计,它必须位于根目录。 If, somehow, you managed to point to one of your subviews, that subview would in essence become the root. 如果以某种方式设法指向一个子视图,则该子视图本质上将成为根。

Comment: 评论:

You do not have to add a view of type animations containing another view of type mainArea . 您不必添加animations类型的视图,其中包含另一个mainArea类型的mainArea You can have 'MainArea inherit from animations , and drag such MainArea` in the storyboard. 您可以让'MainArea inherit from动画inherit from , and drag such在情节提要中, and drag such MainArea`。

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

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