3

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?

Community
  • 1
  • 1
cannyboy
  • 24,180
  • 40
  • 146
  • 252
  • you neet to remeber that computers don't think of holes, they cna only think of full objects, so maybe you would like to use layers? – Trevor Rudolph Dec 10 '11 at 01:56

3 Answers3

10

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::

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

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

[self.window makeKeyAndVisible];
ivanzoid
  • 5,952
  • 2
  • 34
  • 43
  • You would probably want to have a `UIView` property on your app delegate (a la DShah's answer) so you could set `isHidden` on it when you want to reveal/hide it... – Ben Mosher Dec 08 '11 at 12:37
  • When some one says a "hole" you say put the poster of a "hole" on top of it... I like it. – Vincent Bernier Dec 10 '11 at 05:42
3

This could be easy in a way described below :

  • Create a @Property of a UIView in AppDelegate.
  • Create a UIView object and assign to @Property in didFinishLaunching method
  • Simply set the frame of view.
  • Add it as a subView in a mainView (Same as we do in AdMob where we are displaying add in bottom of View on all other subView.)
  • You can access that view from sharedApplication of AppDelegate 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.

DShah
  • 9,768
  • 11
  • 71
  • 127
  • I have added image view from appDelegate and added it in different VCs.But when I navigate to another view or pop the view, the image view disappeared for a while (like a flash) !!! – Maulik Jan 17 '12 at 13:57
  • @Maulik: Does this problem comes on Device?? if on both then did you have used something like addSubview... after processing some operation... this may be the reason.. – DShah Jan 17 '12 at 15:42
  • I have added the image view by addSubView in VC – Maulik Jan 17 '12 at 15:46
  • I am trying to show iAd in multiple screen when iAd is not available the image view should be displayed... – Maulik Jan 17 '12 at 15:48
  • ok.. so in meantime when you are checking for iAds this problem may arise. This may either be because you are looking for network or waiting for timeout of iAds.. this problem will stay... if you dont want such delay then you need some other alternatives... Even if you want to use that... then see to it that you can somehow control the flow or checking your network activity... – DShah Jan 17 '12 at 16:10
  • no its not like that i got the problem. If my current view has added image view from appDelegate and in viewDidLoad of next view if I try to add same image view from appDelegate than it happens.If I use performSelecto....withDelay in next view and than add image view than it works fine !!!! try it – Maulik Jan 17 '12 at 16:22
1

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.