【问题标题】:Making a 'hole' in a UITabBarController or UINavigationController?在 UITabBarController 或 UINavigationController 中打一个“洞”?
【发布时间】:2012-01-10 16:22:20
【问题描述】:

如何在标签栏应用程序中“打孔”,从而基于标签栏的应用程序可以显示每个标签中的 uinavigationcontrollers 后面的视图? (可以选择关闭此打孔器)。

我的代码,应用程序委托,用于创建选项卡是:

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 - Draw transparent rectangle on UIView to reveal view beneath - 但我不知道在我的情况下该怎么做.. 我会将我的导航控制器或标签栏控制器子类化(甚至这样做是否合法),如果是这样,我如何让这个洞成为可选的?

【问题讨论】:

  • 你需要记住,计算机不会想到孔,他们只会想到完整的对象,所以也许你想使用层?

标签: iphone ios uinavigationcontroller uitabbarcontroller


【解决方案1】:

为什么不在 Tab-bar 控制器的顶部添加一个 UIView(它将充当“孔”)?

您可以像这样在application:didFinishLaunchingWithOptions: 中将它添加到应用程序的 UIWindow:

// ...
self.window.rootViewController = self.tabBarController;

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

[self.window makeKeyAndVisible];

【讨论】:

  • 您可能希望在您的应用程序委托上有一个UIView 属性(a la DShah 的回答),这样当您想要显示/隐藏它时,您可以在其上设置isHidden...
  • 当有人说“洞”时,你说把“洞”的海报放在上​​面……我喜欢。
【解决方案2】:

这可能很容易,如下所述:

  • 在 AppDelegate 中创建 UIView@Property
  • 创建一个UIView对象并在didFinishLaunching方法中赋值给@Property
  • 只需设置视图框架。
  • 将其作为子视图添加到主视图中(与我们在 AdMob 中所做的相同,我们在所有其他子视图的视图底部显示添加。)
  • 您可以从sharedApplicationAppDelegate 访问该视图,并且可以显示和隐藏该视图。

就是这样。你需要什么特别的东西??如果这不起作用,请重点说明您的具体要求。

除了上述答案之外,您还可以为 iPhone 选择ToastMessage。您可以使用它来显示和隐藏特定时间的视图。

【讨论】:

  • 我已经从 appDelegate 添加了图像视图,并将其添加到不同的 VC 中。但是当我导航到另一个视图或弹出视图时,图像视图消失了一段时间(就像闪光灯一样)!!!
  • @Maulik:这个问题出现在设备上吗?如果两者都使用过类似 addSubview 的东西...在处理了一些操作之后...这可能是原因..
  • 我在VC中通过addSubView添加了图片视图
  • 当 iAd 不可用时,我正在尝试在多个屏幕中显示 iAd,应该显示图像视图...
  • ok.. 所以在您检查 iAd 的同时,这个问题可能会出现。这可能是因为您正在寻找网络或等待 iAds 超时..这个问题会一直存在......如果你不想要这样的延迟,那么你需要一些其他的选择......即使你想使用它......然后确保您可以以某种方式控制流量或检查您的网络活动...
【解决方案3】:

或在每个选项卡中单独创建一个视图并同步值。详细地说,您将创建一个视图,但将其链接到两个选项卡。只要内存中至少有一个选项卡,就应该自动调节 Retain-Count。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 2019-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多