iPhone/iPad 上的一个屏幕上有多个视图?

发布于 2024-10-10 11:08:06 字数 121 浏览 2 评论 0原文

我想在屏幕顶部构建自定义选项卡菜单,类似于您在 Numbers 应用程序中看到的菜单。 我想我可以将屏幕划分为两个视图:一个位于顶部用于选项卡,另一个较大用于选定的选项卡视图。 这可能吗?我可以有 2 个活动视图和视图控制器吗?

I would like to build custom tab menu on top of the screen, similar to one you see in Numbers app.
I thought I could divide screen beetween two views: one on top for tabs and one bigger for selected tab view.
Is that possible? Can I have 2 active views&view controllers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独难免 2024-10-17 11:08:06

当然有可能。您可以将视图控制器中的视图添加为当前根视图控制器视图的子视图。

这样做(假设这是在 UIViewController 子类中):

UIViewController *newViewController = [[UIViewController alloc] init];
[self.view addSubview:newViewController.view];

完全没问题。

但还要考虑您是否真的需要多个视图控制器而不仅仅是额外的视图。根据我从您的描述中得到的信息,我认为它可以仅使用一个带有附加视图的视图控制器来实现。

关于您的选项卡式菜单实现,不 UITabBarController 满足您的需求吗? iOS 应用程序中的选项卡式界面更常见的是使用这种选项卡栏,而不是选项卡位于顶部的桌面操作系统选项卡栏。

Of course it is possible. You can add views from view controllers as a subview of your current root view controller's view.

Doing this (assume this is inside a UIViewController subclass):

UIViewController *newViewController = [[UIViewController alloc] init];
[self.view addSubview:newViewController.view];

is perfectly fine.

But also consider if you really need multiple view controllers and not just additional views. From what I get from your description, I think it can be implemented with just one view controller with additional views.

Regarding your tabbed menu implementation, doesn't UITabBarController fit your needs? It is more common for tabbed interfaces in iOS apps to use this kind of tab bar, not the desktop OS tab bar where the tabs are at the top.

向地狱狂奔 2024-10-17 11:08:06

正如我从各种来源获得的那样,视图控制器旨在控制占用应用程序窗口的一个视图,因此使用多个视图执行选项卡式菜单是不可能的。

可能有以下可能性:

  • 将当前选项卡位置存储在某个应用程序级单例中
  • 在选择适当的选项卡时添加新视图
  • 选择视图时重绘选项卡菜单(在新视图中或从堆栈中检索)

有人有更好的想法吗?

As I could get from variety of sources, view controller is meant to control one view that occupies application window, so doing tabbed menu with multiple views is not possible.

There may be folowing possibilities:

  • storing current tab position in some king of application level singleton
  • adding new view when appropriate tab is selected
  • redrawing tab menu when view is selected (either in new view or retrieved from stack)

Does anybody have any nicer idea?

万人眼中万个我 2024-10-17 11:08:06

试试这个:

 UIView *contentView1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
 UIView *contentView2=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

 [self.view addSubView:contentView1];
 [self.view addSubView:contentView2];

Try this:

 UIView *contentView1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
 UIView *contentView2=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

 [self.view addSubView:contentView1];
 [self.view addSubView:contentView2];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文