简体   繁体   English

UIViewController作为其他视图控制器的子视图

[英]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.

相关问题 从子视图UIViewcontroller到其他UIViewController - From subview UIViewcontroller to other UIViewController 在UIViewController视图上对子视图进行动画处理 - Animate subview on UIViewController view 带有SubView的tableView的容器视图或UIViewController - Container View or UIViewController for tableView with SubView 将UIViewControllers视图添加为另一个UIViewController视图的子视图 - Add UIViewControllers View as a subView of another UIViewController view 将子视图添加到UIImageView,它是IB中UIViewController的视图出口 - Add a subview to a UIImageView that is the view outlet of a UIViewController in IB 如何将UIViewController的视图作为子视图添加到UITableViewCell? - How to add a UIViewController's view as a subview to a UITableViewCell? 尽管有单独的导航控制器,但重叠了UIViewController子视图内容 - Overlapping UIViewController subview content despite separate navigation controllers 在UIView中作为子视图调用UIViewController视图时出现问题 - Issue in calling UIViewController view as subview in UIView UIPageViewController - 添加的子视图会导致第一个控制器视图中的错误 - 其他控制器很好 - UIPageViewController - added subview causes a bug in the first controller's view - other controllers are fine 如何为某些控制器添加视图作为子视图 - How to add a view as subview for certain controllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM