Shifting the frame of root view controller, containing a tab bar - iphone

The application has a Tabbar Controller as its rootViewController. Now the requirement is on click of a button in the navigation bar, another view should come half way into the screen without any tab bar, and the other half should have the original view that has the tab bar in it. Is this possible to create?
Any help would be appreciated.
EDIT 1:
I did try
[UIApplication sharedApplication].keyWindow.rootViewController.view.frame = CGRectMake();
but the problem is, another view wont be seen in this, as the whole window frame is being shifted.
EDIT 2:
I have added a dummy pic of the requirement.

Create a custom view by subclassing UIView and show that in your current view controller in the first half.
You can use UIKit animation for animating the view if needed.

Finally found the solution to it.
On click of the button,
objThird.view.frame = CGRectMake(120, 0, 320, 480);
UIView *windowVIew = [self.tabBarController.view superview];
[windowVIew addSubview:objThird.view];
self.tabBarController.view.frame = CGRectMake(-200, 0, 320, 480);
objThird = Object of new view that i want when the button is pressed.
self.tabBarController.view superview = Gives you the window view. thus now you can add your view to the window.
And the rest is just playing with the frames of the views.

Related

Hide navigation bar in root view?

I have an application where I'm trying to duplicate what I see the Apple Store app doing, where the first view doesn't have a navigation bar, but subsequent views do.
I've tried various combinations of setting navigationBarHidden to YES and NO to manage when it's visible, but the key problem seems to be that during the transition, it's either visible or it isn't, whereas in the Apple Store app, the navigation bar is not there in the main view, but slides in from the right with the child view.
What I'm looking for is a way to have the navigation bar slide in with the child view, not appear (animated or not) before or after the transition.
Turns out I just hadn't hit on the right places to hide and show the navigation bar.
I used the answer from how to hide navigationbar when i push from navigation controller? and it works great for me now.
in your main view, initialize the childViewController. Then set the nav bar on the childViewController, the push the view controller.
ChildVC *childVC = [[ChildVC alloc] initWithNibName:#"ChildVC" bundle:nil];
[self setChildVC:childVC];
childVC.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:childVC animated:YES];
If you are talking about what they do on the first Tab "Featured", where if you tap one of the items in the list with a disclosure indicator. It appears to slides in another view from right to left. I think they are using an animation to swap two view controllers. The one that slides in IS a Navigation controller which is why NavBar appears to slide in from the right.
You would do something like this to get that effect:
// First set up a view controller with frame set off to the right of the screen.
// Then animate it sliding to the left by setting its frame x = 0;
frame.origin.x = 0;
[UIView animateWithDuration:.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^{
vc.view.frame = frame;
}
completion:nil];

I need my view controller to sit behind my tab bar

I have a view controller, but when I hide the tab bar, there is just a black space where the tab bar was. I want to have my view controller sit behind the tab bar, so when I hide it, it shows the view content. I am using a simple UITabBarController. Thanks.
You can't do this, as far as I'm aware. The problem is that the view controllers sit within the tab bar controller, not the other way around.
The way to get around this would be to change the window view for a new navigation controller without a tab bar controller, or use a modal view to show content without a tab bar controller.
The problem is that your view on your view controller isn't tall enough to accommodate the space that your tab bar occupied.
CGRect current = [[self view] frame];
CGRect tabBarFrame = [[self tabBar] frame];
CGRect newFrame = CGRectMake(current.origin.x, current.origin.y, current.size.width, current.size.height + tabBarFrame.size.height);
[[self view] setFrame:newFrame];
Something like that is probably what you want. Or you can resize it in IB.
But, I don't know why you would use a UITabBarController and then hide the tab bar... If you can't see the tab bar, you cant switch tabs... thus making the UITabBarController pretty much just a UIViewController.
I believe that if you give the view property of your UIViewController a fixed bottom margin and a flexible height then it will stretch to fill the height of containing view automatically.
mycontroller.view.autoresizingMask = UIViewAutoresizingFlexibleHeight

UITabbar still active under another UIView

I have a TabBar on the screen and a View with some buttons on it. When a button is clicked, I create a ViewController (with a view from a nib) and add it to the keywindow of the application. I put this view offscreen and start an animation to make this new view slides from the bottom of the screen, and cover the tabBar. On this new view there is a UIPicker and 2 buttons (select / cancel). When one of this buttons is clicked, the PickerView slide off the screen and his controller is dealloc.
This works fine except for one thing : if I click on the zone where the tabBar is located and hidden by my new view, the tabBar get the click event !
How can I make the tabBar non responsive ? (Remember that I don't push the new view) Or maybe it isn't the right way to do this ?
EDIT & ANSWER : The problem came from the fact that I did a mistake in the height setting. I typed 160 instead of 260.
[myPickerController.view setFrame:CGRectMake(0, 480, 320, 260)];
The last 100 px, even if displayed, where "transparent" to event and get transfered to the TabBar who stands in that zone (even if it was hidden).
I am not sure but why don't you try
yourTabbar.userInteractionEnabled = NO;
when the view is visible. Make sure you set
yourTabbar.userInteractionEnabled = YES;
when view is dismissed.
You should use method named in your application:
tabbar1.hidesBottomBarWhenPushed = YES;

Full screen UIImage view

I have an application with a navigation bar and a tab bar. A user can navigate to a view which displays images in a scroll view. I'd like to have the same behavior as the iPhone photo app: Nav bar at the top, tool bar at the bottom, which will hide or show based upon a tap.
I'm moving my view to the window object in order to achieve full screen mode. This works fine:
myView = [self.view retain];
self.view = nil;
[window addSubview:myView];
But when I want to redisplay the Nav & tool bar, I run into a problem. The bars show fine, but the view is empty, and I can't seem to add any content to the view:
[myView removeFromSuperview];
self.view = myView;
I got a lot of good info from this post
but can't quite get the right combination.
By simply setting the controller's view, you aren't adding it as a subview to anything else, so it will never appear.
Moving views around like this can get a little tricky. I recommend that you not move the view from one to the other, but instead have two UIViews. Add second UIView to the window's subview and set it to hidden=YES initially. When you want to show it, set the image for the UIImageView, and then set the hidden property to NO.
what's wrong with just using setNavigationBarHidden: animated: and setToolbarHidden:animated:?

Persistent UIBarButtonItem in UIToolbar?

I've been developing an iPhone app that uses a UIToolbar (in the context of a UINavigationController) to display a small status icon at the bottom of the screen. The toolbar will eventually also have action icons associated with it (think Mail application).
I'm running into an issue where it appears that each UIViewController pushed onto the navigation controller's stack is expected to have its own set of items for the toolbar to display, and as a result, the "status" item fades out and back in for each view transition.
Is there a way to have a single persistent item in the toolbar? I also tried adding the item in the navigation controller's initializer (I subclassed UINavigationController for this approach), but it's still no go.
Instead of using the navigation controller's toolbar, add one directly to the window and resize the navigation controller's view's frame to avoid it. That single global toolbar will then always be visible.
If you're using the Navigation-based Application template, and are using Interface Builder, the following steps should do it:
Open up your app delegate's .h file.
Add an IBOutlet UIToolbar * toolbar; to the app delegate's instance variables.
Switch to the .m file.
Find the line that reads [window addSubview:[navigationController view]]; and add after it:CGRect frame = navigationController.view.frame;frame.size.height -= toolbar.frame.size.height;navigationController.view.frame = frame;
Add code to release toolbar in the -dealloc method.
Open MainWindow.xib.
Open the window.
Drag a toolbar onto the bottom of the window.
Connect the toolbar to the app delegate's toolbar outlet
Now set up the toolbar—add whatever items you need to it, then create whatever outlets and actions you need in the app delegate and connect them.
Since the toolbar is part of the window, not part of the navigation controller, the navigation controller shouldn't touch it.
As you push new views onto your navigation controller the views in the toolbar will be replaced with the views from the toolbar of the view on the top of the stack.
Even if you have a static view (a view that does not change when you push a new controller), the view will still appear to be new because of the animation apple includes when you push a new view controller onto the stack.
I found this works for me:
CGFloat height = [self.toolbar frame].size.height;
CGRect rootBounds = self.window.rootViewController.view.bounds;
CGRect frame = CGRectMake(0, CGRectGetHeight(rootBounds) - height, CGRectGetWidth(rootBounds), height);
[self.toolbar setFrame:frame];
[self.navigationController.view addSubview:self.toolbar];