[英]UIViewController as a subview for other view controllers
My app has a menu button which is available in every view controller. 我的应用程序有一个菜单按钮,在每个视图控制器中都可用。 Every time a user taps on the menu button, a small menu pops up. 每次用户点击菜单按钮时,都会弹出一个小菜单。 The menu has multiple UIButton
s, and each button links to another view controller. 菜单具有多个UIButton
,每个按钮都链接到另一个视图控制器。
My current solution is to create a view controller with a nib for the menu view and add it as a subview to each of the other main view controllers. 我当前的解决方案是为菜单视图创建一个带有笔尖的视图控制器,并将其作为子视图添加到其他每个主视图控制器中。
Is there is a better solution? 有更好的解决方案吗?
There could be multiple ways of doing it and I don't think there is the best answer. 可能有多种方式,但我认为没有最佳答案。
However, in the performance perspective, implementing a view container such as UINavigationController or UITabBarController would be most effective. 但是,从性能角度来看,实现视图容器(例如UINavigationController或UITabBarController)将是最有效的。
Implement a root view controller (whose view is added as the only direct subview of the application window), and add the menu as a subview of its view. 实现一个根视图控制器(将其视图添加为应用程序窗口的唯一直接子视图),并将菜单添加为其视图的子视图。 Let the root view controller decide (or know) which view to display, and add the view as a subview of its view, below the menu. 让根视图控制器决定(或知道)要显示的视图,并在菜单下方将视图添加为其视图的子视图。
In this way, the view for the menu need not be removed and added again to the current view hierarchy. 这样,无需删除菜单视图并将其再次添加到当前视图层次结构中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.