打一个“洞”在 UITabBarController 或 UINavigationController 中?
我如何在选项卡栏应用程序中“打孔”,从而基于选项卡栏的应用程序可以显示每个选项卡中的 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 - 在 UIView 上绘制透明矩形以显示下面的视图 - 但我不知道如何在我的情况..我是否可以对我的导航控制器或选项卡栏控制器进行子类化(这样做是否合法),如果是这样,我将如何使该孔成为可选的?
How would I 'punch a hole' in a tab bar app, whereby a tab-bar based app can show a view behind the uinavigationcontrollers that are in each tab? (this punch could be optionally turned off).
My code, the the app delegate, for creating the tabs is:
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];
Here's how I'd like it to work:
-----------------------------
| |
| --------------- |
| | | |
| | hole which | |
| | shows the | |
| | same view | |
| | in each tab | |
| --------------- |
| |
| |
-----------------------------
| | |
| tab 1 | tab 2 |
| | |
-----------------------------
There's a thread here about transparent rectangles - iPhone - Draw transparent rectangle on UIView to reveal view beneath - but I'm not sure how to do it in my case.. would I subclass my nav controller or tab bar controller (is it legal to even do that), and if so, how would I make the hole optional?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不在选项卡栏控制器顶部添加一个 UIView(它将充当“洞”)呢?
您可以将其添加到应用程序的 UIWindow 中,如下所示,在
application:didFinishLaunchingWithOptions:
中:Why not just add an UIView (which will act as a "hole") on top of the Tab-bar controller?
You may just add it to application's UIWindow, like this, in
application:didFinishLaunchingWithOptions:
:这可以通过下面描述的方式很容易实现:
UIView
的@Property
。UIView
对象并在didFinishLaunching
方法中分配给@Property
AppDelegate< 的
sharedApplication
访问该视图/code> 您可以显示和隐藏该视图。就是这样。您需要什么特别的?如果这不起作用,请重点说明您的具体要求。
除了上述答案之外,您还可以选择适用于 iPhone 的 ToastMessage。您可以使用它来显示和隐藏给定特定时间的视图。
This could be easy in a way described below :
@Property
of aUIView
in AppDelegate.UIView
object and assign to@Property
indidFinishLaunching
methodsharedApplication
ofAppDelegate
and you can show and hide that view.that's it. What is so special that you need?? If this is not working then please give some highlights of your specific requirement.
Apart from above answer you can also go for a ToastMessage for iPhone. You can use that as to show and hide your view with specific time given.
或者在每个选项卡中单独创建一个视图并同步值。详细来说,您将创建一个视图,但将其链接到两个选项卡。只要内存中至少有一个选项卡,Retain-Count 就应该自动调节。
or create an view in each tab individually and synchronize the values. In detail you would create one view but link it to both tabs. Retain-Count should be regulated automatically as long as at least one tab is in memory.