Adding a persistent UIView with a UITabBarController

I have an application using the UITabBarController, and I have another view that needs to slide due to the tab controls, but before the contents of the tab bar. If this is unclear, imagine an ad deployed in a tabbed application that appears in front of everything except the buttons on the tab bar.

So far I have a code that looks something like this, but I am ready to change it if there is a better way to do this ...

tabBarController.viewControllers = [NSArray arrayWithObjects:locationNavController, emergencyNavController, finderNavController, newsNavController, nil]; aboutView = [[AboutView alloc] initWithFrame:CGRectMake(0, window.frame.size.height - tabBarController.tabBar.frame.size.height - 37 , 320, window.frame.size.height - tabBarController.tabBar.frame.size.height)]; [window addSubview:tabBarController.view]; // adds the tab bar view property to the window [window addSubview:aboutView]; // this is the view that slides in [window makeKeyAndVisible]; 

AboutView is currently a subclass of UIView and is in the starting position at the bottom, but hides the tabBarController. How can I change this so that the tabs are on top, but still have aboutView in front of other content?

+6
objective-c iphone uiview uitabbarcontroller depth
source share
1 answer

You need to add aboutView as the view subzone in the current active view controller in the UITableBarController . You can access this view using the selectedViewController property.

You can add code to your aboutView implementation to animate the view when it appears.

I am doing something similar in the popup view that I want to display under the tab controls. You can add code to the didMoveToSuperview message in the aboutView implementation:

 - (void)didMoveToSuperview { CGRect currentFrame = self.frame; // animate the frame ... this just moves the view up a 10 pixels. You will want to // slide the view all the way to the top CGRect targetFrame = CGRectOffset(currentFrame, 0, -10); // start the animation block and set the offset [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; // animation duration in seconds [UIView setAnimationDelegate:self]; self.frame = targetFrame; [UIView commitAnimations]; } 

Therefore, when your aboutView is added to the selected view of the view controller, it is automatically animated.

+2
source share

All Articles