How to add UIViewController as subview , to be visible above tabbar? - iphone

I want to add the view of a UIViewController as a subview. But self.view is having a UITabBarController. I want to display the subview above tabbar. So that tab bar hides behind subview.
Please suggest some idea.

Try this, if you want to hide/show the UITabBarController of view:
For hide the tabbar:
- (void)hideTabBar:(UITabBarController *) tabbarcontroller
{
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, (isiPhone5?568:480), view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, isiPhone5?568: 480)];
}
}
}
for show Tabbar:
- (void)showTabBar:(UITabBarController *) tabbarcontroller
{
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, (isiPhone5?519:431), view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, isiPhone5?519:431)];
}
}
}
may be it will help.

Where you alloc and initialize TabBar, write this line
objectOfTabbar.hidden=YES;
Then give the frame of your subview same as of TabBarController.
This way your tabbar will be hidden and view will be shown .

Related

Tab Bar Hides when Navigate

I have Four Tabs in My Project By Default First tab is selected which is Home Class When user navigate to any other class by selecting any tab i have to check that time that if user is loggedin in my application then he will navigate to class which he selected else he move to Login Screen.
if(appDelegate.sessionId==0)
{
Login *objLogin=[[[Login alloc] initWithNibName:#"Login" bundle:nil] autorelease];
[self.navigationController pushViewController:objLogin animated:YES];
}
else
{
CreatePoll *objLogin=[[[CreatePoll alloc] initWithNibName:#"CreatePoll" bundle:nil] autorelease];
[self.navigationController pushViewController:objLogin animated:YES];
}
}
IF i navigate to Login Screen my tab bar gets Hidden and when i debug the code i came to know that Create Poll class is also get called in background i check this link to show tab bar which is hidden but cant get success. Please help me guys i m stucked with this problem from last 3 days.
Cant see my tabbar in Login Screen.Please Help
just write this code in viewWillAppear: method to hide and show the UITabBar
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.tabBarController.tabBar setHidden:NO];
UPDATE:
post these method in AppDelegate.m file and when you want to show and hide the Tabbar at that time create AppDelegate object and call this method
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}

Hiding and Unhiding of tabbar

I have a tabbar controller. I want to hide the tab bar in a view and want to unhide the same tabbar in the next view.The hidding code is working for the first view but in the second view where i am unhiding the tab bar it is not working..
My code:
For Hiding:
[[self navigationController] setHidesBottomBarWhenPushed:YES];
For Unhiding:
[[self navigationController] setHidesBottomBarWhenPushed:NO];
.h
- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;
- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;
.m
- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{
[UIView transitionWithView:tabbarcontroller.tabBar duration:duration options: UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
} completion:^(BOOL finished) {
NSLog(#"tabbar hidden");
}];
}
- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{
[UIView transitionWithView:tabbarcontroller.tabBar duration:duration options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
} completion:^(BOOL finished) {
NSLog(#"tabbar shown");
}];
//u can call like this
//[self hideTabBarOfThisTabbarController:self.tabBarCon withAnimationDuration:3];
//if u want immediately hide/show the tabbar then duration should be 0.0

How to hide the tab bar on click of a tab in an iPhone app

I am doing a multi view app, in that I have 4 tabs, and I have view controllers in each tab. In one tab I have grouped table view controller, on click of that tab it will go to that grouped table view. Every thing is going fine.
But last row of the table is hidden under tab bar, so I need to hide the tab bar when I enter into that screen. How can I do this?
I am using this in Appdelegate to create tabs programmatically.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *localNavigationController;
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:5];
//add first tab View Controller
RootViewController *ViewController;
ViewController = [[RootViewController alloc] initWithTabBar];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:ViewController];
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[ViewController release];
//add second tab View Controller
StudentDataEntry *GroupViewController;
GroupViewController = [[StudentDataEntry alloc] initWithTabBar];
localNavigationController = [[UINavigationController alloc]
initWithRootViewController:GroupViewController];
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[GroupViewController release];
}
if your last row is not visible in your view then there is no need to hide tab bar for that you have to make your table view height according to that, a tab bar is 48 px so minus this 48 px height from your table view height and also if there is a navigation bar at the top then also minus 44 more px from height then it will be visible. And also you can set content inset for table view to make it visible.
Try this
yourviewcontroller.hidesBottomBarWhenPushed=YES;
Try this:
BOOL hiddenTabBar = NO;
- (void) hidetabbar {
NSArray *array = self.tabBarController.view.subviews;
NSLog(#"array SubView %#",array);
[UIView animateWithDuration:1.0 delay:0.0f options:UIViewAnimationCurveLinear animations:^(){
for(UIView *view in self.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
} else {
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
} completion:^(BOOL isfinsihed){
hiddenTabBar = !hiddenTabBar;
}];
}

UITabBar wont hide

I have a UINavigationController in a UITabBarController, and I can't seem to get a pushed viewController's tabBar to hide.
I am using the following code to hide it:
Before it gets pushed:
tpsv.hidesBottomBarWhenPushed = YES;
tpsv.tabBarController.hidesBottomBarWhenPushed = YES;
viewWillAppear:
self.tabBarController.tabBar.hidden = YES;
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[[del tabController] tabBar]setHidden:YES];
But none of the above work.
If you could tell me how to fix this, that would be great.
You set this before you push the new view controller:
MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
myVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myVC animated:YES];
[EDIT: comment re usage]
Just noticed you say you tried this. Not sure what else you're doing in the context of pushing your VC or configuring it but this does work fine. It's how I do this exact thing in my apps.
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
I've faced the same problem with
myVC.hidesBottomBarWhenPushed = YES;
It does'nt remove the tab bar in subsequent views. May be it's deprecated. You should'nt face this problem with the setHidesBottomBarWhenPushed: command. Try using the following for views:
MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
[myVC setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:myVC animated:YES];

Iphone TabBar Application

I start to develop app in tab bar application template..
Here my first page is login page after loagin it go to home page and all navigation will happen..
Here i don't want tab bar only in login page.How to doo this?
Thanks.....
on the first tab, add whatever check you need for whether or not they are logged in, and if not, present a modal view with the login fields.
//some test here to determine state of self.registered
if(self.registered==FALSE){
LoginViewController *login = [[LoginViewController alloc] initWithNibName: #"loginView" bundle: nil];
login.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentModalViewController:login animated:YES];
[login release];
}
With this you can hide and how uitabbarcontroller -
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
You can do like this:
In delegate.h declare your views,
UIView *indicatorView;
UIImageView *splashV;
now in delegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 320, 460)];
[splashV setImage:[UIImage imageNamed:#"Default.png"]];
[indicatorView setBackgroundColor:[UIColor clearColor]];
[indicatorView addSubview:splashV];
[self.window addSubview:indicatorView];
}
& on successful login
-(void)SuccessfulLoginDone
{
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
}
Hope that would be much better to do this task.