在UITabBarController或UINavigationController中制作'hole'?



我如何在标签栏应用程序中"打一个洞",使基于标签栏的应用程序可以在每个标签中的导航控制器后面显示视图?(这个冲床可以选择性地关闭)。

我的代码,app委托,用于创建选项卡:

OneRootViewController *oneRootViewController = [[OneRootViewController alloc] initWithNibName:@"OneRootViewController" bundle:nil];
UINavigationController *oneNav = [[UINavigationController alloc] initWithRootViewController:oneRootViewController];
oneNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"One" image:[UIImage imageNamed:@"one.png"] tag:0];
TwoRootViewController *twoRootViewController = [[TwoRootViewController alloc] initWithNibName:@"TwoRootViewController" bundle:nil];
UINavigationController *twoNav = [[UINavigationController alloc] initWithRootViewController:twoRootViewController];
twoNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Two" image:[UIImage imageNamed:@"two.png"] tag:1];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:oneNav, twoNav, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

我希望它是这样工作的:

-----------------------------
|                           |
|     ---------------       |
|     |             |       |
|     | hole which  |       |
|     | shows the   |       |
|     | same view   |       |
|     | in each tab |       |
|     ---------------       |
|                           |
|                           |
-----------------------------
|            |              |
|   tab 1    |   tab 2      |
|            |              |
-----------------------------

有一个线程这里关于透明矩形- iPhone -绘制透明矩形在UIView显示视图下面-但我不确定如何在我的情况下做到这一点。我是否要子类化我的导航控制器或标签栏控制器(这样做是否合法),如果合法,我该如何让这个洞成为可选的?

为什么不添加一个UIView(这将作为一个"洞")在标签栏控制器的顶部?

你可以把它添加到应用程序的ui窗口,像这样,在application:didFinishLaunchingWithOptions::

// ...
self.window.rootViewController = self.tabBarController;
MyView *holeView = [[MyView alloc] initWithFrame:CGRectMake(hole coordinates)];
[self.window addSubview:holeView];
[holeView release];
[self.window makeKeyAndVisible];

这很简单,方法如下:

  • 在AppDelegate中创建UIView@Property
  • 创建UIView对象并在didFinishLaunching方法中分配给@Property
  • 简单地设置视图框架。
  • 将其添加为mainView中的子视图(与我们在AdMob中所做的相同,我们在所有其他子视图的视图底部显示Add)
  • 您可以从sharedApplicationAppDelegate访问该视图,并且可以显示和隐藏该视图。

就是这样。你需要什么特别的东西?如果这行不通,那么请强调一下你的具体要求。

除了上面的答案,你也可以去ToastMessage的iPhone。你可以用它来显示和隐藏特定时间的视图

或者在每个选项卡中单独创建一个视图并同步值。具体来说,您将创建一个视图,但将其链接到两个选项卡。keep - count应该自动调节,只要至少有一个选项卡在内存中。

最新更新